private boolean isDeprecated(IJavaElement element) throws JavaModelException { if (element instanceof ITypeRoot) { return Flags.isDeprecated(((ITypeRoot) element).findPrimaryType().getFlags()); } 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; }
/** * Checks whether the given Java element has accessible source. * * @param je the Java element to test * @return <code>true</code> if the element has source * @since 3.2 */ private static boolean hasSource(ITypeRoot je) { if (je == null || !je.exists()) return false; try { return je.getBuffer() != null; } catch (JavaModelException ex) { IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex); //$NON-NLS-1$ JavaPlugin.getDefault().getLog().log(status); } return false; }
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]; }
ITypeRoot typeRoot= astRoot.getTypeRoot(); try { if (typeRoot != null && typeRoot.getBuffer() != null) { IBuffer buffer= typeRoot.getBuffer(); int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition(); int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength(); String str= buffer.getText(offset, length); if (removeIndent) { IJavaProject project= typeRoot.getJavaProject(); int indent= getIndentUsed(buffer, node.getStartPosition(), project); str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
} else if (this.typeRoot instanceof IClassFile) { try { String sourceString = this.typeRoot.getSource(); if (sourceString != null) { this.rawSource = sourceString.toCharArray(); } else if (this.typeRoot instanceof IClassFile) { try { String sourceString = this.typeRoot.getSource(); if (sourceString == null) { throw new IllegalStateException(); PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent(); BinaryType type = (BinaryType) this.typeRoot.findPrimaryType(); IBinaryType binaryType = (IBinaryType) type.getElementInfo();
} else if (this.typeRoot instanceof IClassFile) { try { String sourceString = this.typeRoot.getSource(); if (sourceString != null) { this.rawSource = sourceString.toCharArray(); } else if (this.typeRoot instanceof IClassFile) { try { String sourceString = this.typeRoot.getSource(); if (sourceString == null) { throw new IllegalStateException(); PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent(); BinaryType type = (BinaryType) this.typeRoot.findPrimaryType(); String fileNameString = null; if (type != null) { } else { fileNameString = this.typeRoot.getElementName();
packageInfo = packageFragment.getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA); if (packageInfo != null && packageInfo.exists()) { String cuSource = packageInfo.getSource(); element = ((IOrdinaryClassFile) packageInfo).getType(); } else { element = packageInfo.getParent(); // parent is the IPackageFragment
public TextEdit getDeleteEdit() { final ASTRewrite rewriter= ASTRewrite.create(fDeclaration.getAST()); rewriter.remove(fDeclaration, null); return rewriter.rewriteAST(fDocument, fTypeRoot.getJavaProject().getOptions(true)); }
private IJavaElement getEnclosingMethod(ITypeRoot input, ITextSelection selection) { try { IJavaElement enclosingElement= input.getElementAt(selection.getOffset()); if (enclosingElement instanceof IMethod || enclosingElement instanceof IInitializer || enclosingElement instanceof IField) { // opening on the enclosing type would be too confusing (since the type resolves to the constructors) return enclosingElement; } } catch (JavaModelException e) { JavaPlugin.log(e); } return null; }
/** * Creates a TokenScanner * @param typeRoot The type root to scan on * @throws CoreException thrown if the buffer cannot be accessed */ public TokenScanner(ITypeRoot typeRoot) throws CoreException { IJavaProject project= typeRoot.getJavaProject(); IBuffer buffer= typeRoot.getBuffer(); if (buffer == null) { throw new CoreException(createError(DOCUMENT_ERROR, "Element has no source", null)); //$NON-NLS-1$ } String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true); fScanner= ToolFactory.createScanner(true, false, true, sourceLevel, complianceLevel); // line info required fScanner.setSource(buffer.getCharacters()); fDocument= null; // use scanner for line information fEndPosition= fScanner.getSource().length - 1; }
protected String getPathInFragmentRoot(final ITypeRoot derivedResource) { return derivedResource.getParent().getElementName().replace('.', '/') + "/"; }
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; }
/** * 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(); }
private int getOffset(TextDocumentPositionParams param, ITypeRoot typeRoot) { int offset = 0; try { IDocument document = JsonRpcHelpers.toDocument(typeRoot.getBuffer()); offset = document.getLineOffset(param.getPosition().getLine()) + param.getPosition().getCharacter(); } catch (JavaModelException | BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return offset; }
if (this.typeRoot.getElementType() == IJavaElement.COMPILATION_UNIT) { ICompilationUnit original = (org.eclipse.jdt.core.ICompilationUnit)this.typeRoot;
private String findRecommendedLineSeparator(CompilationUnit astRoot) { try { return astRoot.getTypeRoot().findRecommendedLineSeparator(); } catch (JavaModelException e) { throw new UnhandledException(astRoot, e); } }
private void exportClassFiles(IProgressMonitor progressMonitor, ITypeRoot typeRootElement, IPath destinationPath) { if (fJarPackage.areClassFilesExported()) { try { if (!typeRootElement.exists()) return; // find corresponding file(s) on classpath and export Iterator iter= filesOnClasspath(typeRootElement, destinationPath, progressMonitor); IPath baseDestinationPath= destinationPath.removeLastSegments(1); while (iter.hasNext()) { IFile file= (IFile)iter.next(); IPath classFilePath= baseDestinationPath.append(file.getName()); progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); fJarWriter.write(file, classFilePath); } } catch (CoreException ex) { addToStatus(ex); } } }
ITypeRoot typeRoot= astRoot.getTypeRoot(); try { if (typeRoot != null && typeRoot.getBuffer() != null) { IBuffer buffer= typeRoot.getBuffer(); int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition(); int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength(); String str= buffer.getText(offset, length); if (removeIndent) { IJavaProject project= typeRoot.getJavaProject(); int indent= StubUtility.getIndentUsed(buffer, node.getStartPosition(), project); str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());