List of usage examples for org.eclipse.jdt.core ITypeRoot getElementName
String getElementName();
From source file:ca.uvic.chisel.javasketch.ui.internal.MarkTypeJob.java
License:Open Source License
/** * @param name//from w w w. j a va2 s .c om */ public MarkTypeJob(ITypeRoot typeRoot) { super("Marking Touched Locations in " + typeRoot.getElementName()); this.typeRoot = typeRoot; }
From source file:org.eclipse.che.jdt.javadoc.ASTProvider.java
License:Open Source License
/** * Creates a new compilation unit AST./*from w w w .j a v a2 s .co m*/ * * @param input the Java element for which to create the AST * @param progressMonitor the progress monitor * @return AST */ public static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) { if (!hasSource(input)) return null; if (progressMonitor != null && progressMonitor.isCanceled()) return null; final ASTParser parser = ASTParser.newParser(SHARED_AST_LEVEL); parser.setResolveBindings(true); parser.setStatementsRecovery(SHARED_AST_STATEMENT_RECOVERY); parser.setBindingsRecovery(SHARED_BINDING_RECOVERY); parser.setSource(input); if (progressMonitor != null && progressMonitor.isCanceled()) return null; final CompilationUnit root[] = new CompilationUnit[1]; SafeRunner.run(new ISafeRunnable() { public void run() { try { if (progressMonitor != null && progressMonitor.isCanceled()) return; if (DEBUG) System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ root[0] = (CompilationUnit) parser.createAST(progressMonitor); //mark as unmodifiable ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT); } catch (OperationCanceledException ex) { return; } } public void handleException(Throwable ex) { LOG.error(ex.getMessage(), ex); } }); return root[0]; }
From source file:org.eclipse.che.plugin.java.server.JavaNavigation.java
License:Open Source License
/** * Get the compilation unit representation of the java file. * * @param javaProject/*w w w .j a v a 2s . c om*/ * path to the project which is contained class file * @param fqn * fully qualified name of the class file * @param isShowingInheritedMembers * <code>true</code> iff inherited members are shown * @return instance of {@link CompilationUnit} * @throws JavaModelException * when JavaModel has a failure */ public CompilationUnit getCompilationUnitByPath(IJavaProject javaProject, String fqn, boolean isShowingInheritedMembers) throws JavaModelException { IType type = javaProject.findType(fqn); CompilationUnit compilationUnit = DtoFactory.newDto(CompilationUnit.class); ITypeRoot unit; if (type.isBinary()) { unit = type.getClassFile(); compilationUnit.setPath(((IClassFile) unit).getType().getFullyQualifiedName()); } else { unit = type.getCompilationUnit(); compilationUnit.setProjectPath(unit.getJavaProject().getPath().toOSString()); compilationUnit.setPath(unit.getResource().getFullPath().toOSString()); } compilationUnit.setElementName(unit.getElementName()); compilationUnit.setHandleIdentifier(unit.getHandleIdentifier()); compilationUnit.setLabel(org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(unit, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT)); List<Type> types = new ArrayList<>(1); Type dtoType = convertToDTOType(type); dtoType.setPrimary(true); types.add(dtoType); compilationUnit.setTypes(types); if (isShowingInheritedMembers) { compilationUnit.setSuperTypes(calculateSuperTypes(type)); } return compilationUnit; }
From source file:org.eclipse.edt.ide.ui.internal.property.pages.BasicElementLabels.java
License:Open Source License
/** * Returns a label for a type root name which is a file name. * //from w w w .jav a 2s. co m * @param typeRoot the typeRoot * @return the label of the resource name. */ public static String getFileName(ITypeRoot typeRoot) { return StringUtility.markLTR(typeRoot.getElementName()); }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java
License:Open Source License
@Override public void endVisit(final org.eclipse.jdt.core.dom.CompilationUnit node) { CompilationUnit element = (CompilationUnit) this.binding.get(node); // if any type of this cu already exists in the model, we don't // visit this cu if (this.isAlreadyVisited) { return;// w w w . ja v a2 s . c om } this.jdtModel.getCompilationUnits().add(element); ITypeRoot rootType = node.getTypeRoot(); if (rootType != null) { if (rootType instanceof IClassFile) { // type comes from a .class file ClassFile classFile = this.factory.createClassFile(); classFile.setName(rootType.getElementName()); classFile.setAttachedSource(element); classFile.setOriginalFilePath(this.currentFilePath); Archive ar = LibraryReader.getArchive((IClassFile) rootType, this.factory, this.jdtModel); if (ar == null) { this.jdtModel.getClassFiles().add(classFile); } else { ar.getClassFiles().add(classFile); } } else if (rootType instanceof ICompilationUnit) { // type comes a .java file IPath absolutePath = null; try { absolutePath = rootType.getCorrespondingResource().getLocation(); } catch (JavaModelException e) { absolutePath = ResourcesPlugin.getWorkspace().getRoot().getRawLocation() .append(rootType.getPath()); } element.setOriginalFilePath(absolutePath.toOSString()); } else { element.setOriginalFilePath(""); //$NON-NLS-1$ } element.setName(rootType.getElementName()); } else { element.setProxy(true); } Package packageDeclaration = (Package) this.binding.get(node.getPackage()); element.setPackage(packageDeclaration); for (Object importNode : node.imports()) { ImportDeclaration importDeclaration = (ImportDeclaration) this.binding.get(importNode); element.getImports().add(importDeclaration); } for (Object typeNode : node.types()) { AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) this.binding.get(typeNode); element.getTypes().add(typeDeclaration); } try { // accessing BlockComment and LineComment // (https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=84528) List<?> comments = node.getCommentList(); for (Object name : comments) { org.eclipse.jdt.core.dom.Comment aComment = (org.eclipse.jdt.core.dom.Comment) name; Comment commentElement = null; if (aComment.isLineComment()) { commentElement = this.factory.createLineComment(); initializeNode(commentElement, aComment); String content = CommentsManager.extractCommentContent(aComment, this.javaContent); commentElement.setContent(content); this.binding.put(aComment, commentElement); } else if (aComment.isBlockComment()) { commentElement = this.factory.createBlockComment(); initializeNode(commentElement, aComment); String content = CommentsManager.extractCommentContent(aComment, this.javaContent); commentElement.setContent(content); this.binding.put(aComment, commentElement); } else if (aComment.isDocComment()) { // one javadoc node (and its tag elements) should have been // already visited commentElement = (Javadoc) this.binding.get(aComment); if (commentElement == null) { // happen if more than one javadoc // for a node commentElement = this.factory.createJavadoc(); initializeNode(commentElement, aComment); } commentElement.setContent(aComment.toString()); } getCommentsBinding().put(aComment, commentElement); // initialisation of element CompilationUnit element.getCommentList().add(commentElement); } CommentsManager.resolveCommentPositions(this); } catch (StringIndexOutOfBoundsException e) { // IGNORE hub, sam, markus } }
From source file:org.eclipse.xtext.common.types.ui.trace.TraceForTypeRootProvider.java
License:Open Source License
protected Charset getSourceEncoding(final ITypeRoot derivedJavaType) { // this should be symmetric to org.eclipse.jdt.internal.core.SourceMapper.findSource(String) try {// www . j a v a 2s . com IJavaElement current = derivedJavaType.getParent(); while (current != null) { if (current instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) current; try { // see org.eclipse.jdt.internal.core.ClasspathEntry.getSourceAttachmentEncoding() IClasspathAttribute[] attributes = root.getResolvedClasspathEntry().getExtraAttributes(); for (int i = 0, length = attributes.length; i < length; i++) { IClasspathAttribute attribute = attributes[i]; if (SOURCE_ATTACHMENT_ENCODING.equals(attribute.getName())) return Charset.forName(attribute.getValue()); } } catch (JavaModelException e) { } return Charset.forName(ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset()); } current = current.getParent(); } return Charset.forName(ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset()); } catch (CoreException e) { log.error("Error determining encoding for source file for " + derivedJavaType.getElementName(), e); return Charsets.UTF_8; } }
From source file:org.jboss.tools.vscode.java.internal.handlers.DocumentHighlightHandler.java
License:Open Source License
private List<DocumentHighlight> computeOccurrences(ITypeRoot unit, int line, int column) { if (unit != null) { try {//from w w w . j av a 2 s . c o m int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column); OccurrencesFinder finder = new OccurrencesFinder(); ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(unit); parser.setResolveBindings(true); ASTNode ast = parser.createAST(new NullProgressMonitor()); if (ast instanceof CompilationUnit) { finder.initialize((CompilationUnit) ast, offset, 0); List<DocumentHighlight> result = new ArrayList<>(); OccurrenceLocation[] occurrences = finder.getOccurrences(); if (occurrences != null) { for (OccurrenceLocation loc : occurrences) { result.add(convertToHighlight(unit, loc)); } } return result; } } catch (JavaModelException e) { JavaLanguageServerPlugin .logException("Problem with compute occurrences for" + unit.getElementName(), e); } } return Collections.emptyList(); }
From source file:org.jboss.tools.vscode.java.internal.handlers.DocumentSymbolHandler.java
License:Open Source License
private SymbolInformation[] getOutline(ITypeRoot unit) { try {/*from w w w . j ava 2s. co m*/ IJavaElement[] elements = unit.getChildren(); ArrayList<SymbolInformation> symbols = new ArrayList<SymbolInformation>(elements.length); collectChildren(unit, elements, symbols); return symbols.toArray(new SymbolInformation[symbols.size()]); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem getting outline for" + unit.getElementName(), e); } return new SymbolInformation[0]; }
From source file:org.jboss.tools.vscode.java.internal.handlers.NavigateToDefinitionHandler.java
License:Open Source License
private Location computeDefinitonNavigation(ITypeRoot unit, int line, int column) { try {/* w w w. ja v a 2s .co m*/ IJavaElement[] elements = unit.codeSelect(JsonRpcHelpers.toOffset(unit.getBuffer(), line, column), 0); if (elements == null || elements.length != 1) return null; IJavaElement element = elements[0]; ICompilationUnit compilationUnit = (ICompilationUnit) element .getAncestor(IJavaElement.COMPILATION_UNIT); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (compilationUnit != null || (cf != null && cf.getSourceRange() != null)) { return JDTUtils.toLocation(element); } return null; } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem with codeSelect for" + unit.getElementName(), e); } return null; }