use of org.eclipse.jdt.core.JavaModelException in project tdi-studio-se by Talend.
the class JobHierarchyLifeCycle method ensureRefreshedTypeHierarchy.
public void ensureRefreshedTypeHierarchy(final IProcess2 element, IRunnableContext context) throws InvocationTargetException, InterruptedException {
if (element == null) {
freeHierarchy();
return;
}
// boolean hierachyCreationNeeded = (fHierarchy == null || !element.equals(inputProcess));
boolean hierachyCreationNeeded = true;
if (hierachyCreationNeeded || fHierarchyRefreshNeeded) {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
try {
doHierarchyRefresh(element, pm);
} catch (JavaModelException e) {
throw new InvocationTargetException(e);
} catch (OperationCanceledException e) {
throw new InterruptedException();
}
}
};
fHierarchyRefreshNeeded = true;
context.run(true, true, op);
fHierarchyRefreshNeeded = false;
}
}
use of org.eclipse.jdt.core.JavaModelException in project bndtools by bndtools.
the class GeneralInfoPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
section.setText("Basic Information");
KeyStroke assistKeyStroke = null;
try {
assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
} catch (ParseException x) {
// Ignore
}
FieldDecoration contentAssistDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
toolkit.createLabel(composite, "Version:");
txtVersion = toolkit.createText(composite, "", SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtVersion, Constants.BUNDLE_VERSION);
Hyperlink linkActivator = toolkit.createHyperlink(composite, "Activator:", SWT.NONE);
txtActivator = toolkit.createText(composite, "", SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtActivator, Constants.BUNDLE_ACTIVATOR);
toolkit.createLabel(composite, "Declarative Services:");
cmbComponents = new Combo(composite, SWT.READ_ONLY);
// Content Proposal for the Activator field
ContentProposalAdapter activatorProposalAdapter = null;
ActivatorClassProposalProvider proposalProvider = new ActivatorClassProposalProvider();
activatorProposalAdapter = new ContentProposalAdapter(txtActivator, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
activatorProposalAdapter.addContentProposalListener(proposalProvider);
activatorProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
activatorProposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());
activatorProposalAdapter.setAutoActivationDelay(1000);
// Decorator for the Activator field
ControlDecoration decorActivator = new ControlDecoration(txtActivator, SWT.LEFT | SWT.CENTER, composite);
decorActivator.setImage(contentAssistDecoration.getImage());
decorActivator.setMarginWidth(3);
if (assistKeyStroke == null) {
decorActivator.setDescriptionText("Content Assist is available. Start typing to activate");
} else {
decorActivator.setDescriptionText(MessageFormat.format("Content Assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
}
decorActivator.setShowOnlyOnFocus(true);
decorActivator.setShowHover(true);
// Decorator for the Components combo
ControlDecoration decorComponents = new ControlDecoration(cmbComponents, SWT.LEFT | SWT.CENTER, composite);
decorComponents.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
decorComponents.setMarginWidth(3);
decorComponents.setDescriptionText("Use Java annotations to detect Declarative Service Components.");
decorComponents.setShowOnlyOnFocus(false);
decorComponents.setShowHover(true);
// Listeners
txtVersion.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
addDirtyProperty(Constants.BUNDLE_VERSION);
}
});
}
});
cmbComponents.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
ComponentChoice old = componentChoice;
int index = cmbComponents.getSelectionIndex();
if (index >= 0 && index < ComponentChoice.values().length) {
componentChoice = ComponentChoice.values()[cmbComponents.getSelectionIndex()];
if (old != componentChoice) {
addDirtyProperty(aQute.bnd.osgi.Constants.SERVICE_COMPONENT);
addDirtyProperty(aQute.bnd.osgi.Constants.DSANNOTATIONS);
if (old == null) {
cmbComponents.remove(ComponentChoice.values().length);
}
}
}
}
});
}
});
txtActivator.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
addDirtyProperty(Constants.BUNDLE_ACTIVATOR);
}
});
}
});
linkActivator.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent ev) {
String activatorClassName = txtActivator.getText();
if (activatorClassName != null && activatorClassName.length() > 0) {
try {
IJavaProject javaProject = getJavaProject();
if (javaProject == null)
return;
IType activatorType = javaProject.findType(activatorClassName);
if (activatorType != null) {
JavaUI.openInEditor(activatorType, true, true);
}
} catch (PartInitException e) {
ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening an editor for activator class '{0}'.", activatorClassName), e));
} catch (JavaModelException e) {
ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error searching for activator class '{0}'.", activatorClassName), e));
}
}
}
});
activatorProposalAdapter.addContentProposalListener(new IContentProposalListener() {
@Override
public void proposalAccepted(IContentProposal proposal) {
if (proposal instanceof JavaContentProposal) {
String selectedPackageName = ((JavaContentProposal) proposal).getPackageName();
if (!model.isIncludedPackage(selectedPackageName)) {
model.addPrivatePackage(selectedPackageName);
}
}
}
});
// Layout
GridLayout layout = new GridLayout(2, false);
layout.horizontalSpacing = 15;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
txtVersion.setLayoutData(gd);
txtActivator.setLayoutData(gd);
cmbComponents.setLayoutData(gd);
}
use of org.eclipse.jdt.core.JavaModelException in project bndtools by bndtools.
the class AbstractBuildErrorDetailsHandler method createMethodMarkerData.
/**
* Create a marker on a Java Method
*
* @param javaProject
* @param className
* - the fully qualified class name (e.g java.lang.String)
* @param methodName
* @param methodSignature
* - signatures are in "internal form" e.g. (Ljava.lang.Integer;[Ljava/lang/String;Z)V
* @param markerAttributes
* - attributes that should be included in the marker, typically a message. The start and end points for
* the marker are added by this method.
* @param hasResolutions
* - true if the marker will have resolutions
* @return Marker Data that can be used to create an {@link IMarker}, or null if no location can be found
* @throws JavaModelException
*/
public static final MarkerData createMethodMarkerData(IJavaProject javaProject, final String className, final String methodName, final String methodSignature, final Map<String, Object> markerAttributes, boolean hasResolutions) throws JavaModelException {
final CompilationUnit ast = createAST(javaProject, className);
if (ast == null)
return null;
ast.accept(new ASTVisitor() {
@Override
public boolean visit(MethodDeclaration methodDecl) {
if (matches(ast, methodDecl, methodName, methodSignature)) {
// Create the marker attribs here
markerAttributes.put(IMarker.CHAR_START, methodDecl.getStartPosition());
markerAttributes.put(IMarker.CHAR_END, methodDecl.getStartPosition() + methodDecl.getLength());
}
return false;
}
private boolean matches(CompilationUnit ast, MethodDeclaration methodDecl, String methodName, String signature) {
if ("<init>".equals(methodName)) {
if (!methodDecl.isConstructor()) {
return false;
}
} else if (!methodDecl.getName().getIdentifier().equals(methodName)) {
return false;
}
return getSignature(ast, methodDecl).equals(signature);
}
private String getSignature(CompilationUnit ast, MethodDeclaration methodDecl) {
StringBuilder signatureBuilder = new StringBuilder("(");
for (@SuppressWarnings("unchecked") Iterator<SingleVariableDeclaration> it = methodDecl.parameters().iterator(); it.hasNext(); ) {
SingleVariableDeclaration decl = it.next();
appendType(ast, signatureBuilder, decl.getType(), decl.getExtraDimensions());
}
signatureBuilder.append(")");
appendType(ast, signatureBuilder, methodDecl.getReturnType2(), 0);
return signatureBuilder.toString();
}
private void appendType(CompilationUnit ast, StringBuilder signatureBuilder, Type typeToAdd, int extraDimensions) {
for (int i = 0; i < extraDimensions; i++) {
signatureBuilder.append('[');
}
Type rovingType = typeToAdd;
if (rovingType == null) {
//A special return type for constructors, nice one Eclipse...
signatureBuilder.append("V");
} else {
if (rovingType.isArrayType()) {
ArrayType type = (ArrayType) rovingType;
int depth = type.getDimensions();
for (int i = 0; i < depth; i++) {
signatureBuilder.append('[');
}
//We still need to add the array component type, which might be primitive or a reference
rovingType = type.getElementType();
}
// Type erasure means that we should ignore parameters
if (rovingType.isParameterizedType()) {
rovingType = ((ParameterizedType) rovingType).getType();
}
if (rovingType.isPrimitiveType()) {
PrimitiveType type = (PrimitiveType) rovingType;
signatureBuilder.append(PRIMITIVES_TO_SIGNATURES.get(type.getPrimitiveTypeCode()));
} else if (rovingType.isSimpleType()) {
SimpleType type = (SimpleType) rovingType;
String name;
if (type.getName().isQualifiedName()) {
name = type.getName().getFullyQualifiedName();
} else {
name = getFullyQualifiedNameForSimpleName(ast, type.getName());
}
name = name.replace('.', '/');
signatureBuilder.append("L").append(name).append(";");
} else if (rovingType.isQualifiedType()) {
QualifiedType type = (QualifiedType) rovingType;
String name = type.getQualifier().toString().replace('.', '/') + '/' + type.getName().getFullyQualifiedName().replace('.', '/');
signatureBuilder.append("L").append(name).append(";");
} else {
throw new IllegalArgumentException("We hit an unknown type " + rovingType);
}
}
}
private String getFullyQualifiedNameForSimpleName(CompilationUnit ast, Name typeName) {
String name = typeName.getFullyQualifiedName();
@SuppressWarnings("unchecked") List<ImportDeclaration> ids = ast.imports();
for (ImportDeclaration id : ids) {
if (id.isStatic())
continue;
if (id.isOnDemand()) {
String packageName = id.getName().getFullyQualifiedName();
try {
if (ast.getJavaElement().getJavaProject().findType(packageName + "." + name) != null) {
name = packageName + '.' + name;
}
} catch (JavaModelException e) {
}
} else {
String importName = id.getName().getFullyQualifiedName();
if (importName.endsWith("." + name)) {
name = importName;
break;
}
}
}
if (name.indexOf('.') < 0) {
try {
if (ast.getJavaElement().getJavaProject().findType(name) == null) {
name = "java.lang." + name;
}
} catch (JavaModelException e) {
}
}
return name;
}
});
if (!markerAttributes.containsKey(IMarker.CHAR_START))
return null;
return new MarkerData(ast.getJavaElement().getResource(), markerAttributes, hasResolutions);
}
use of org.eclipse.jdt.core.JavaModelException in project xtext-xtend by eclipse.
the class ConvertJavaCode method runJavaConverter.
public void runJavaConverter(final Set<ICompilationUnit> compilationUnits, Shell activeShell) throws ExecutionException {
Map<ICompilationUnit, ConversionResult> conversionResults = newHashMap();
boolean canceled = convertAllWithProgress(activeShell, compilationUnits, conversionResults);
if (canceled) {
return;
}
boolean hasConversionFailures = any(conversionResults.values(), new Predicate<ConversionResult>() {
@Override
public boolean apply(ConversionResult input) {
return input.getProblems().iterator().hasNext();
}
});
if (hasConversionFailures) {
ConversionProblemsDialog problemsDialog = new ConversionProblemsDialog(activeShell, conversionResults);
problemsDialog.open();
if (problemsDialog.getReturnCode() == Window.CANCEL) {
return;
}
}
final String storedValue = dialogs.getUserDecision(DELETE_JAVA_FILES_AFTER_CONVERSION);
boolean deleteJavaFiles = false;
if (MessageDialogWithToggle.PROMPT.equals(storedValue)) {
int userAnswer = dialogs.askUser("Delete Java source files?", "Xtend converter", DELETE_JAVA_FILES_AFTER_CONVERSION, activeShell);
if (userAnswer == IDialogConstants.CANCEL_ID) {
// cancel
return;
} else if (userAnswer == IDialogConstants.YES_ID) {
deleteJavaFiles = true;
}
} else if (MessageDialogWithToggle.ALWAYS.equals(storedValue)) {
deleteJavaFiles = true;
}
for (final Entry<ICompilationUnit, ConversionResult> result : conversionResults.entrySet()) {
ICompilationUnit compilationUnit = result.getKey();
ConversionResult conversionResult = result.getValue();
String xtendCode = conversionResult.getXtendCode();
IFile xtendFileToCreate = xtendFileToCreate(compilationUnit);
if (!conversionResult.getProblems().iterator().hasNext()) {
String formattedCode = formatXtendCode(xtendFileToCreate, xtendCode);
if (formattedCode != null) {
xtendCode = formattedCode;
}
}
writeToFile(xtendFileToCreate, xtendCode);
if (deleteJavaFiles) {
try {
compilationUnit.delete(true, null);
} catch (JavaModelException e) {
handleException("Unable to delete Java file.", e, compilationUnit.getResource());
}
}
}
}
use of org.eclipse.jdt.core.JavaModelException in project xtext-xtend by eclipse.
the class XtendUIValidator method isInSourceFolder.
protected boolean isInSourceFolder(IJavaProject javaProject, IFile resource) {
IPath path = resource.getFullPath();
IClasspathEntry[] classpath;
try {
classpath = javaProject.getResolvedClasspath(true);
} catch (JavaModelException e) {
// not a Java project
return false;
}
for (int i = 0; i < classpath.length; i++) {
IClasspathEntry entry = classpath[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPath entryPath = entry.getPath();
if (entryPath.isPrefixOf(path)) {
return true;
}
}
}
return false;
}
Aggregations