blob: 47bf0e840481bd7e1510415fd997972615a3675d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.capra.handler.cdt;
import org.eclipse.capra.core.adapters.ArtifactMetaModelAdapter;
import org.eclipse.capra.core.handlers.AnnotationException;
import org.eclipse.capra.core.handlers.ArtifactHandler;
import org.eclipse.capra.core.handlers.IAnnotateArtifact;
import org.eclipse.capra.core.helpers.ExtensionPointHelper;
import org.eclipse.capra.handler.cdt.preferences.CDTPreferences;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.emf.ecore.EObject;
/**
* Handler to allow tracing to and from elements of C such as files and
* functions. Uses CDT as the foundation.
*/
public class CDTHandler implements ArtifactHandler, IAnnotateArtifact {
@Override
public boolean canHandleSelection(Object selection) {
return selection instanceof ICElement;
}
@Override
public EObject getEObjectForSelection(Object selection, EObject artifactModel) {
ICElement cu = (ICElement) selection;
ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
EObject wrapper = adapter.createArtifact(artifactModel, this.getClass().getName(), cu.getHandleIdentifier(),
cu.getElementName());
return wrapper;
}
@Override
public ICElement resolveArtifact(EObject artifact) {
ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
String uri = adapter.getArtifactUri(artifact);
return CoreModel.create(uri);
}
@Override
public String getDisplayName(Object selection) {
ICElement cu = (ICElement) selection;
return cu.getElementName();
}
@Override
public void annotateArtifact(EObject artifact, String annotation) throws AnnotationException {
IEclipsePreferences preferences = CDTPreferences.getPreferences();
if (preferences.getBoolean(CDTPreferences.ANNOTATE_CDT, CDTPreferences.ANNOTATE_CDT_DEFAULT)) {
ICElement handle = resolveArtifact(artifact);
CDTAnnotate.annotateArtifact(handle, annotation);
}
}
}