<commit_before>/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.hammer.validation.issues;

import org.eclipse.swt.graphics.Image;

import com.archimatetool.help.hints.IHelpHintProvider;
import com.archimatetool.model.IArchimateComponent;
import com.archimatetool.model.IDiagramModelArchimateConnection;
import com.archimatetool.model.IDiagramModelArchimateObject;





/**
 * Issue Type
 * 
 * @author <NAME>
 */
public abstract class AbstractIssueType implements IIssue {
    
    private String fName = ""; //$NON-NLS-1$
    private String fDescription = ""; //$NON-NLS-1$
    private String fExplanation = ""; //$NON-NLS-1$
    private Object fObject;
    
    protected AbstractIssueType() {
    }
    
    /**
     * @param name The name of the Issue
     * @param description The description of the Issue
     * @param explanation The explnation of the Issue
     * @param obj The object in question
     */
    protected AbstractIssueType(String name, String description, String explanation, Object obj) {
        setName(name);
        setDescription(description);
        setExplanation(explanation);
        setObject(obj);
    }

    public void setName(String name) {
        fName = name;
    }

    public String getName() {
        return fName;
    }
    
    public void setDescription(String description) {
        fDescription = description;
    }

    public String getDescription() {
        return fDescription;
    }
    
    public void setExplanation(String explanation) {
        fExplanation = explanation;
    }
    
    public String getExplanation() {
        return fExplanation;
    }
    
    public void setObject(Object obj) {
        fObject = obj;
    }
    
    public Object getObject() {
        return fObject;
    }
    
    public Image getImage() {
        return null;
    }
    
    public String getHelpHintTitle() {
        return getName();
    }
    
    public String getHelpHintContent() {
        return getExplanation();
    }
    
    @SuppressWarnings({"rawtypes", "unchecked"})
    public Object getAdapter(Class adapter) {
        Object object = getObject();
        
        if(object == null || adapter == null) {
            return null;
        }
        
        if(adapter == IHelpHintProvider.class) {
            return this;
        }
        
        if(adapter.isInstance(object) || adapter.isInstance(this)) {
            return object;
        }
        
        if(adapter.isAssignableFrom(IArchimateComponent.class)) {
            if(object instanceof IDiagramModelArchimateObject) {
                return ((IDiagramModelArchimateObject)object).getArchimateElement();
            }
            if(object instanceof IDiagramModelArchimateConnection) {
                return ((IDiagramModelArchimateConnection)object).getRelationship();
            }
        }
        
        return null;
    }
}<commit_msg>[Hammer] Ensure AbstractIssueType returns Hint when object is null<commit_after>/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.hammer.validation.issues;

import org.eclipse.swt.graphics.Image;

import com.archimatetool.help.hints.IHelpHintProvider;
import com.archimatetool.model.IArchimateComponent;
import com.archimatetool.model.IDiagramModelArchimateConnection;
import com.archimatetool.model.IDiagramModelArchimateObject;





/**
 * Issue Type
 * 
 * @author <NAME>
 */
public abstract class AbstractIssueType implements IIssue {
    
    private String fName = ""; //$NON-NLS-1$
    private String fDescription = ""; //$NON-NLS-1$
    private String fExplanation = ""; //$NON-NLS-1$
    private Object fObject;
    
    protected AbstractIssueType() {
    }
    
    /**
     * @param name The name of the Issue
     * @param description The description of the Issue
     * @param explanation The explnation of the Issue
     * @param obj The object in question
     */
    protected AbstractIssueType(String name, String description, String explanation, Object obj) {
        setName(name);
        setDescription(description);
        setExplanation(explanation);
        setObject(obj);
    }

    public void setName(String name) {
        fName = name;
    }

    public String getName() {
        return fName;
    }
    
    public void setDescription(String description) {
        fDescription = description;
    }

    public String getDescription() {
        return fDescription;
    }
    
    public void setExplanation(String explanation) {
        fExplanation = explanation;
    }
    
    public String getExplanation() {
        return fExplanation;
    }
    
    public void setObject(Object obj) {
        fObject = obj;
    }
    
    public Object getObject() {
        return fObject;
    }
    
    public Image getImage() {
        return null;
    }
    
    public String getHelpHintTitle() {
        return getName();
    }
    
    public String getHelpHintContent() {
        return getExplanation();
    }
    
    @SuppressWarnings({"rawtypes", "unchecked"})
    public Object getAdapter(Class adapter) {
        if(adapter == IHelpHintProvider.class) {
            return this;
        }
        
        Object object = getObject();
        if(object == null) {
            return null;
        }
        
        if(adapter.isInstance(object) || adapter.isInstance(this)) {
            return object;
        }
        
        if(adapter.isAssignableFrom(IArchimateComponent.class)) {
            if(object instanceof IDiagramModelArchimateObject) {
                return ((IDiagramModelArchimateObject)object).getArchimateElement();
            }
            if(object instanceof IDiagramModelArchimateConnection) {
                return ((IDiagramModelArchimateConnection)object).getRelationship();
            }
        }
        
        return null;
    }
}
{'fraction_non_alphanumeric': 0.08671374609952373, 'fraction_numerical': 0.0009853834784036787, 'mean_word_length': 2.324235807860262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '835461', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1627, 'n_words': 402}