/** * Returns a string for the given Java element used for debugging. * * @param javaElement the compilation unit AST * @return a string used for debugging */ private String toString(ITypeRoot javaElement) { if (javaElement == null) return "null"; //$NON-NLS-1$ else return javaElement.getElementName(); }
/** * Returns a string for the given Java element used for debugging. * * @param javaElement the compilation unit AST * @return a string used for debugging */ public String toString(ITypeRoot javaElement) { if (javaElement == null) return "null"; //$NON-NLS-1$ else return javaElement.getElementName(); }
/** * Returns a label for a type root name which is a file name. * * @param typeRoot the typeRoot * @return the label of the resource name. */ public static String getFileName(ITypeRoot typeRoot) { return Strings.markLTR(typeRoot.getElementName()); }
/** * Returns a label for a type root name which is a file name. * * @param typeRoot the typeRoot * @return the label of the resource name. */ public static String getFileName(ITypeRoot typeRoot) { return Strings.markLTR(typeRoot.getElementName()); }
private static boolean processJavadocComments(CompilationUnit astRoot) { // don't visit Javadoc for 'package-info' (bug 216432) if (astRoot != null && astRoot.getTypeRoot() != null) { return !JavaModelUtil.PACKAGE_INFO_JAVA.equals(astRoot.getTypeRoot().getElementName()); } return true; }
private static boolean processJavadocComments(CompilationUnit astRoot) { // don't visit Javadoc for 'package-info' (bug 216432) if (astRoot != null && astRoot.getTypeRoot() != null) { return !JavaModelUtil.PACKAGE_INFO_JAVA.equals(astRoot.getTypeRoot().getElementName()); } return true; }
private SymbolInformation[] getOutline(ITypeRoot unit, IProgressMonitor monitor) { try { IJavaElement[] elements = unit.getChildren(); ArrayList<SymbolInformation> symbols = new ArrayList<>(elements.length); collectChildren(unit, elements, symbols, monitor); return symbols.toArray(new SymbolInformation[symbols.size()]); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem getting outline for" + unit.getElementName(), e); } return new SymbolInformation[0]; }
private List<DocumentSymbol> getHierarchicalOutline(ITypeRoot unit, IProgressMonitor monitor) { try { return Stream.of(filter(unit.getChildren())).map(child -> toDocumentSymbol(child, monitor)).filter(Objects::nonNull).collect(Collectors.toList()); } catch (OperationCanceledException e) { logInfo("User abort while collecting the document symbols."); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem getting outline for" + unit.getElementName(), e); } return emptyList(); }
@Override public void run() { try { if (progressMonitor != null && progressMonitor.isCanceled()) return; if (JavaPlugin.DEBUG_AST_PROVIDER) 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; } } @Override
public boolean equals(Object o) { if (this == o) return true; /* I see cases where equal lambdas are dismissed as unequal on account of working copy owner. This results in spurious failures. See JavaSearchBugs8Tests.testBug400905_0021() For now exclude the working copy owner and compare */ if (o instanceof LambdaExpression) { LambdaExpression that = (LambdaExpression) o; if (this.sourceStart != that.sourceStart) return false; ITypeRoot thisTR = this.getTypeRoot(); ITypeRoot thatTR = that.getTypeRoot(); return thisTR.getElementName().equals(thatTR.getElementName()) && thisTR.getParent().equals(thatTR.getParent()); } return false; }
public boolean equals(Object o) { if (this == o) return true; /* I see cases where equal lambdas are dismissed as unequal on account of working copy owner. This results in spurious failures. See JavaSearchBugs8Tests.testBug400905_0021() For now exclude the working copy owner and compare */ if (o instanceof LambdaExpression) { LambdaExpression that = (LambdaExpression) o; if (this.sourceStart != that.sourceStart) return false; ITypeRoot thisTR = this.getTypeRoot(); ITypeRoot thatTR = that.getTypeRoot(); return thisTR.getElementName().equals(thatTR.getElementName()) && thisTR.getParent().equals(thatTR.getParent()); } return false; }
public boolean equals(Object o) { if (this == o) return true; /* I see cases where equal lambdas are dismissed as unequal on account of working copy owner. This results in spurious failures. See JavaSearchBugs8Tests.testBug400905_0021() For now exclude the working copy owner and compare */ if (o instanceof LambdaExpression) { LambdaExpression that = (LambdaExpression) o; if (this.sourceStart != that.sourceStart) return false; ITypeRoot thisTR = this.getTypeRoot(); ITypeRoot thatTR = that.getTypeRoot(); return thisTR.getElementName().equals(thatTR.getElementName()) && thisTR.getParent().equals(thatTR.getParent()); } return false; }
public boolean equals(Object o) { if (this == o) return true; /* I see cases where equal lambdas are dismissed as unequal on account of working copy owner. This results in spurious failures. See JavaSearchBugs8Tests.testBug400905_0021() For now exclude the working copy owner and compare */ if (o instanceof LambdaExpression) { LambdaExpression that = (LambdaExpression) o; if (this.sourceStart != that.sourceStart) return false; ITypeRoot thisTR = this.getTypeRoot(); ITypeRoot thatTR = that.getTypeRoot(); return thisTR.getElementName().equals(thatTR.getElementName()) && thisTR.getParent().equals(thatTR.getParent()); } return false; }
@Override public boolean equals(Object o) { if (this == o) return true; /* I see cases where equal lambdas are dismissed as unequal on account of working copy owner. This results in spurious failures. See JavaSearchBugs8Tests.testBug400905_0021() For now exclude the working copy owner and compare */ if (o instanceof LambdaExpression) { LambdaExpression that = (LambdaExpression) o; if (this.sourceStart != that.sourceStart) return false; ITypeRoot thisTR = this.getTypeRoot(); ITypeRoot thatTR = that.getTypeRoot(); return thisTR.getElementName().equals(thatTR.getElementName()) && thisTR.getParent().equals(thatTR.getParent()); } return false; }
@Override public void run() { try { if (progressMonitor != null && progressMonitor.isCanceled()) return; if (JavaManipulationPlugin.DEBUG_AST_PROVIDER) 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; } } @Override
/** * Returns the file name where the node comes from, or "FakeClass.java" if this is a fake node. * * @param node the node * @return the file name where the node comes from, or "FakeClass.java" if this is a fake node. */ public static String getFileName(ASTNode node) { if (node.getRoot() instanceof CompilationUnit) { CompilationUnit cu = (CompilationUnit) node.getRoot(); if (cu.getTypeRoot() != null) { // added for unit tests return cu.getTypeRoot().getElementName(); } return "FakeClass.java"; } return null; }
private List<DocumentHighlight> computeOccurrences(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { if (unit != null) { try { int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column); OccurrencesFinder finder = new OccurrencesFinder(); CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor); if (ast != null) { String error = finder.initialize(ast, offset, 0); if (error == null){ List<DocumentHighlight> result = new ArrayList<>(); OccurrenceLocation[] occurrences = finder.getOccurrences(); if (occurrences != null) { for (OccurrenceLocation loc : occurrences) { if (monitor.isCanceled()) { return Collections.emptyList(); } result.add(convertToHighlight(unit, loc)); } } return result; } } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName(), e); } } return Collections.emptyList(); }
/** * Returns a string suitable for identifying a location in the source. * * @param node the node from which to retrieve the source location * @return a string suitable for identifying a location in the source */ public static String getSourceLocation(ASTNode node) { final ASTNode root = node != null ? node.getRoot() : null; if (root instanceof CompilationUnit) { final CompilationUnit cu = (CompilationUnit) root; final int position = node.getStartPosition(); final int line = cu.getLineNumber(position); final int column = cu.getColumnNumber(position) + 1; if (cu.getTypeRoot() != null) { return cu.getTypeRoot().getElementName() + ":" + line + ":" + column; } // it was not created from a file return line + ":" + column; } return ""; }
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { try { IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor); if (element == null) { return null; } 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 fixLocation(element, JDTUtils.toLocation(element), unit.getJavaProject()); } if (element instanceof IMember && ((IMember) element).getClassFile() != null) { return fixLocation(element, JDTUtils.toLocation(((IMember) element).getClassFile()), unit.getJavaProject()); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem computing definition for" + unit.getElementName(), e); } return null; }
JavaLanguageServerPlugin.logException("Problem computing typeDefinition for" + unit.getElementName(), e);