List of usage examples for org.eclipse.jdt.core IMember isBinary
boolean isBinary();
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isAbstract(IMember member) throws JavaModelException { int flags = member.getFlags(); if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) { return !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags); }//from w w w . j a v a 2 s.com return Flags.isAbstract(flags); }
From source file:ch.powerunit.poweruniteclipse.tab.PowerUnitLaunchTabClass.java
License:Open Source License
public void initializeClazz(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { String name = null;// www . ja v a 2 s. c om if (javaElement instanceof IMember) { IMember member = (IMember) javaElement; if (member.isBinary()) { javaElement = member.getClassFile(); } else { javaElement = member.getCompilationUnit(); } } if (javaElement instanceof ICompilationUnit) { try { name = ((ICompilationUnit) javaElement).getTypes()[0].getFullyQualifiedName(); } catch (JavaModelException e) { // TODO } } else if (javaElement instanceof IClassFile) { name = ((IClassFile) javaElement).getType().getFullyQualifiedName(); } if (name == null) { name = EMPTY_STRING; } config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, name); if (name.length() > 0) { int index = name.lastIndexOf('.'); if (index > 0) { name = name.substring(index + 1); } name = parent.getLaunchConfigurationDialog().generateName(name); config.rename(name); } }
From source file:com.aliyun.odps.eclipse.launch.configuration.udf.SharedUDFClassTab.java
License:Apache License
/** * Set the main type & name attributes on the working copy based on the IJavaElement */// ww w .j a va 2s . co m protected void initializeMainTypeAndName(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { String name = null; if (javaElement instanceof IMember) { IMember member = (IMember) javaElement; if (member.isBinary()) { javaElement = member.getClassFile(); } else { javaElement = member.getCompilationUnit(); } } if (javaElement instanceof ICompilationUnit || javaElement instanceof IClassFile) { try { IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaElement }, false); MainMethodSearchEngine engine = new MainMethodSearchEngine(); IType[] types = engine.searchMainMethods(getLaunchConfigurationDialog(), scope, false); if (types != null && (types.length > 0)) { // Simply grab the first main type found in the searched element name = types[0].getFullyQualifiedName(); } } catch (InterruptedException ie) { JDIDebugUIPlugin.log(ie); } catch (InvocationTargetException ite) { JDIDebugUIPlugin.log(ite); } } if (name == null) { name = EMPTY_STRING; } config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, name); if (name.length() > 0) { int index = name.lastIndexOf('.'); if (index > 0) { name = name.substring(index + 1); } name = getLaunchConfigurationDialog().generateName(name); config.rename(name); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
public void searchDeclarations(IJavaElement enclosingElement, SearchRequestor requestor, SearchPattern pattern, IProgressMonitor monitor) throws JavaModelException { if (VERBOSE) { Util.verbose(" - java element: " + enclosingElement); //$NON-NLS-1$ }/* w ww . j av a 2 s . c om*/ IJavaSearchScope scope = createJavaSearchScope(new IJavaElement[] { enclosingElement }); IResource resource = ((JavaElement) enclosingElement).resource(); if (enclosingElement instanceof IMember) { IMember member = (IMember) enclosingElement; ICompilationUnit cu = member.getCompilationUnit(); if (cu != null) { resource = cu.getResource(); } else if (member.isBinary()) { // binary member resource cannot be used as this // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=148215 resource = null; } } try { if (resource instanceof IFile) { try { requestor.beginReporting(); if (VERBOSE) { Util.verbose("Searching for " + pattern + " in " + resource.getFullPath()); //$NON-NLS-1$//$NON-NLS-2$ } SearchParticipant participant = getDefaultSearchParticipant(indexManager); SearchDocument[] documents = MatchLocator.addWorkingCopies(pattern, new SearchDocument[] { new JavaSearchDocument(enclosingElement.getPath().toString(), participant) }, getWorkingCopies(enclosingElement), participant); participant.locateMatches(documents, pattern, scope, requestor, monitor); } finally { requestor.endReporting(); } } else { search(pattern, new SearchParticipant[] { getDefaultSearchParticipant(indexManager) }, scope, requestor, monitor); } } catch (CoreException e) { if (e instanceof JavaModelException) throw (JavaModelException) e; throw new JavaModelException(e); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Visit the given type declaration and report the nodes that match exactly the * search pattern (i.e. the ones in the matching nodes set) *///from www.j a v a 2 s .co m protected void reportMatching(TypeDeclaration type, IJavaElement parent, int accuracy, MatchingNodeSet nodeSet, int occurrenceCount) throws CoreException { // create type handle IJavaElement enclosingElement = parent; if (enclosingElement == null) { enclosingElement = createTypeHandle(new String(type.name)); } else if (enclosingElement instanceof IType) { enclosingElement = ((IType) parent).getType(new String(type.name)); } else if (enclosingElement instanceof IMember) { IMember member = (IMember) parent; if (member.isBinary()) { enclosingElement = ((IClassFile) this.currentPossibleMatch.openable).getType(); } else { enclosingElement = member.getType(new String(type.name), occurrenceCount); } } if (enclosingElement == null) return; boolean enclosesElement = encloses(enclosingElement); // report the type declaration if (accuracy > -1 && enclosesElement) { int offset = type.sourceStart; SearchMatch match = this.patternLocator.newDeclarationMatch(type, enclosingElement, type.binding, accuracy, type.sourceEnd - offset + 1, this); report(match); } boolean matchedClassContainer = (this.matchContainer & PatternLocator.CLASS_CONTAINER) != 0; // report the type parameters if (type.typeParameters != null) { reportMatching(type.typeParameters, enclosingElement, parent, type.binding, nodeSet); } // report annotations if (type.annotations != null) { reportMatching(type.annotations, enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement); } // report references in javadoc if (type.javadoc != null) { ASTNode[] nodes = nodeSet.matchingNodes(type.declarationSourceStart, type.sourceStart); if (nodes != null) { if (!matchedClassContainer) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); if (enclosesElement) { this.patternLocator.matchReportReference(node, enclosingElement, null, null, type.binding, level.intValue(), this); } } } } } // super types if ((type.bits & ASTNode.IsAnonymousType) != 0) { TypeReference superType = type.allocation.type; if (superType != null) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superType, enclosingElement, null, null, type.binding, level.intValue(), this); } } else { TypeReference superClass = type.superclass; if (superClass != null) { reportMatchingSuper(superClass, enclosingElement, type.binding, nodeSet, matchedClassContainer); } TypeReference[] superInterfaces = type.superInterfaces; if (superInterfaces != null) { for (int i = 0, l = superInterfaces.length; i < l; i++) { reportMatchingSuper(superInterfaces[i], enclosingElement, type.binding, nodeSet, matchedClassContainer); } } } // filter out element not in hierarchy scope boolean typeInHierarchy = type.binding == null || typeInHierarchy(type.binding); matchedClassContainer = matchedClassContainer && typeInHierarchy; // Visit fields FieldDeclaration[] fields = type.fields; if (fields != null) { if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported FieldDeclaration[] otherFields = null; int first = -1; int length = fields.length; for (int i = 0; i < length; i++) { FieldDeclaration field = fields[i]; boolean last = field.endPart2Position == 0 || field.declarationEnd == field.endPart2Position; // Store first index of multiple field declaration if (!last) { if (first == -1) { first = i; } } if (first >= 0) { // Store all multiple fields but first one for other elements if (i > first) { if (otherFields == null) { otherFields = new FieldDeclaration[length - i]; } otherFields[i - 1 - first] = field; } // On last field, report match with all other elements if (last) { for (int j = first; j <= i; j++) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(fields[j]); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(fields[j], otherFields, type, enclosingElement, value, typeInHierarchy, nodeSet); } first = -1; otherFields = null; } } else { // Single field, report normally Integer level = (Integer) nodeSet.matchingNodes.removeKey(field); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(field, null, type, enclosingElement, value, typeInHierarchy, nodeSet); } } } // Visit methods AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported for (int i = 0, l = methods.length; i < l; i++) { AbstractMethodDeclaration method = methods[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(method); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(method, type, enclosingElement, value, typeInHierarchy, nodeSet); } } // Visit types TypeDeclaration[] memberTypes = type.memberTypes; if (memberTypes != null) { for (int i = 0, l = memberTypes.length; i < l; i++) { if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported TypeDeclaration memberType = memberTypes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(memberType); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(memberType, enclosingElement, value, nodeSet, 1); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.HandleFactory.java
License:Open Source License
/** * Create handle by adding child to parent obtained by recursing into parent scopes. *//*w ww. j a v a 2 s . co m*/ private IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit, HashSet existingElements, HashMap knownScopes) { IJavaElement newElement = (IJavaElement) knownScopes.get(scope); if (newElement != null) return newElement; switch (scope.kind) { case Scope.COMPILATION_UNIT_SCOPE: newElement = unit; break; case Scope.CLASS_SCOPE: IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes); switch (parentElement.getElementType()) { case IJavaElement.COMPILATION_UNIT: newElement = ((ICompilationUnit) parentElement) .getType(new String(scope.enclosingSourceType().sourceName)); break; case IJavaElement.TYPE: newElement = ((IType) parentElement).getType(new String(scope.enclosingSourceType().sourceName)); break; case IJavaElement.FIELD: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: IMember member = (IMember) parentElement; if (member.isBinary()) { return null; } else { newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1); // increment occurrence count if collision is detected if (newElement != null) { while (!existingElements.add(newElement)) ((SourceRefElement) newElement).occurrenceCount++; } } break; } if (newElement != null) { knownScopes.put(scope, newElement); } break; case Scope.METHOD_SCOPE: IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes); MethodScope methodScope = (MethodScope) scope; if (methodScope.isInsideInitializer()) { // inside field or initializer, must find proper one TypeDeclaration type = methodScope.referenceType(); int occurenceCount = 1; int length = type.fields == null ? 0 : type.fields.length; for (int i = 0; i < length; i++) { FieldDeclaration field = type.fields[i]; if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) { switch (field.getKind()) { case AbstractVariableDeclaration.FIELD: case AbstractVariableDeclaration.ENUM_CONSTANT: newElement = parentType.getField(new String(field.name)); break; case AbstractVariableDeclaration.INITIALIZER: newElement = parentType.getInitializer(occurenceCount); break; } break; } else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) { occurenceCount++; } } } else { // method element AbstractMethodDeclaration method = methodScope.referenceMethod(); newElement = parentType.getMethod(new String(method.selector), Util.typeParameterSignatures(method)); if (newElement != null) { knownScopes.put(scope, newElement); } } break; case Scope.BLOCK_SCOPE: // standard block, no element per se newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes); break; } return newElement; }
From source file:com.redhat.ceylon.eclipse.code.hover.DocumentationHover.java
License:Open Source License
private static void appendJavadoc(IJavaElement elem, StringBuilder sb) { if (elem instanceof IMember) { try {//w ww .j a va 2s. c o m //TODO: Javadoc @ icon? IMember mem = (IMember) elem; String jd = JavadocContentAccess2.getHTMLContent(mem, true); if (jd != null) { sb.append("<br/>").append(jd); String base = getBaseURL(mem, mem.isBinary()); int endHeadIdx = sb.indexOf("</head>"); sb.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); } } catch (JavaModelException e) { e.printStackTrace(); } } }
From source file:edu.buffalo.cse.green.editor.controller.MemberPart.java
License:Open Source License
/** * @return The part's corresponding javadoc. *//* www .j a v a 2 s .c om*/ private String getJavaDoc() { final IMember element = (IMember) model().getJavaElement(); int type = element.isBinary() ? CLASS_FILE : COMPILATION_UNIT; CompilationUnit cu = getEditor().getCompilationUnit(element.getAncestor(type)); //If no source code attached for given element if (cu == null) return ""; JavadocGrabber grabber = getJavadocGrabber(); grabber.setElement(model().getMember()); cu.accept(grabber); return grabber.getJavadoc(); }
From source file:edu.buffalo.cse.green.relationships.RelationshipVisitor.java
License:Open Source License
/** * @param element - The member element./* ww w. j av a 2 s . c om*/ * @return A <code>CompilationUnit</code> representing the structure of the * source code of the element. */ public static CompilationUnit getCompilationUnit(IMember element) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); if (element.isBinary()) { parser.setSource((IClassFile) element.getAncestor(IJavaElement.CLASS_FILE)); } else { parser.setSource((ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT)); } return (CompilationUnit) parser.createAST(null); }
From source file:org.eclipse.ajdt.internal.ui.refactoring.pullout.PullOutRefactoring.java
License:Open Source License
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException, OperationCanceledException { RefactoringStatus status = new RefactoringStatus(); monitor.beginTask("Checking preconditions...", 1); try {/*from ww w .j a v a2 s. c om*/ if (memberMap == null || memberMap.isEmpty()) status.merge(RefactoringStatus.createFatalErrorStatus("No pullout targets have been specified.")); else { for (ICompilationUnit cu : memberMap.keySet()) { for (IMember member : memberMap.get(cu)) { if (!member.exists()) { status.merge(RefactoringStatus.createFatalErrorStatus(MessageFormat.format( "Member ''{0}'' does not exist.", new Object[] { member.getElementName() }))); } else if (!isInTopLevelType(member)) { status.merge(RefactoringStatus.createFatalErrorStatus(MessageFormat.format( "Member ''{0}'' is not directly nested in a top-level type.", new Object[] { member.getElementName() }))); } else if (member.isBinary()) { status.merge(RefactoringStatus.createFatalErrorStatus(MessageFormat.format( "Member ''{0}'' is not in source code. Binary methods can not be refactored.", new Object[] { member.getElementName() }))); } else if (!member.getCompilationUnit().isStructureKnown()) { status.merge(RefactoringStatus.createFatalErrorStatus( MessageFormat.format("Compilation unit ''{0}'' contains compile errors.", new Object[] { cu.getElementName() }))); } } } } } finally { monitor.done(); } return status; }