本文整理汇总了Java中org.eclipse.jdt.core.ITypeRoot类的典型用法代码示例。如果您正苦于以下问题:Java ITypeRoot类的具体用法?Java ITypeRoot怎么用?Java ITypeRoot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITypeRoot类属于org.eclipse.jdt.core包,在下文中一共展示了ITypeRoot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConstantValue
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
/**
* Returns the constant value for the given field.
*
* @param field the field
* @param editorInputElement the editor input element
* @param hoverRegion the hover region in the editor
* @return the constant value for the given field or <code>null</code> if none
* @since 3.4
*/
private static String getConstantValue(IField field, ITypeRoot editorInputElement, IRegion hoverRegion) {
if (!isStaticFinal(field))
return null;
ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion);
if (node == null)
return null;
Object constantValue= getVariableBindingConstValue(node, field);
if (constantValue == null)
return null;
if (constantValue instanceof String) {
return ASTNodes.getEscapedStringLiteral((String) constantValue);
} else {
return getHexConstantValue(constantValue);
}
}
示例2: launch
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
@Override
public void launch(IEditorPart editor, String mode) {
ITypeRoot element= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
if (element != null) {
launch(new Object[] { element }, mode);
}
}
示例3: getAST
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
public CompilationUnit getAST(final ITypeRoot input, IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) {
return null;
}
if (!shouldCache(input)) {
JavaLanguageServerPlugin.logInfo("Creating uncached AST for " + input.getPath().toString());
return createAST(input, progressMonitor);
}
final String identifier = input.getHandleIdentifier();
return cache.computeIfAbsent(identifier, k -> {
JavaLanguageServerPlugin.logInfo("Caching AST for " + input.getPath().toString());
CompilationUnit astRoot = createAST(input, progressMonitor);
astCreationCount++;
return astRoot;
});
}
示例4: getNodeSource
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
/**
* Returns the source of the given node from the location where it was parsed.
* @param node the node to get the source from
* @param extendedRange if set, the extended ranges of the nodes should ne used
* @param removeIndent if set, the indentation is removed.
* @return return the source for the given node or null if accessing the source failed.
*/
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
ASTNode root= node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit astRoot= (CompilationUnit) root;
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());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}
示例5: internalGetContentReader
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
/**
* Gets a reader for an package fragment's Javadoc comment content from the source attachment.
* The content does contain only the text from the comment without the Javadoc leading star characters.
* Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
* @param fragment The package fragment to get the Javadoc of.
* @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
* does not contain a Javadoc comment or if no source is available
* @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
* @since 3.4
*/
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
IPackageFragmentRoot root= (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
//1==> Handle the case when the documentation is present in package-info.java or package-info.class file
boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY;
ITypeRoot packageInfo;
if (isBinary) {
packageInfo= fragment.getClassFile(PACKAGE_INFO_CLASS);
} else {
packageInfo= fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
}
if (packageInfo != null && packageInfo.exists()) {
String source = packageInfo.getSource();
//the source can be null for some of the class files
if (source != null) {
Javadoc javadocNode = getPackageJavadocNode(fragment, source);
if (javadocNode != null) {
int start = javadocNode.getStartPosition();
int length = javadocNode.getLength();
return new JavaDocCommentReader(source, start, start + length - 1);
}
}
}
return null;
}
示例6: getExpressionBaseName
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
private static String getExpressionBaseName(Expression expr) {
IBinding argBinding= Bindings.resolveExpressionBinding(expr, true);
if (argBinding instanceof IVariableBinding) {
IJavaProject project= null;
ASTNode root= expr.getRoot();
if (root instanceof CompilationUnit) {
ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot();
if (typeRoot != null) {
project= typeRoot.getJavaProject();
}
}
return StubUtility.getBaseName((IVariableBinding)argBinding, project);
}
if (expr instanceof SimpleName) {
return ((SimpleName) expr).getIdentifier();
}
return null;
}
示例7: convertToHighlight
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
private DocumentHighlight convertToHighlight(ITypeRoot unit, OccurrenceLocation occurrence)
throws JavaModelException {
DocumentHighlight h = new DocumentHighlight();
if ((occurrence.getFlags() | IOccurrencesFinder.F_WRITE_OCCURRENCE) == IOccurrencesFinder.F_WRITE_OCCURRENCE) {
h.setKind(DocumentHighlightKind.Write);
} else if ((occurrence.getFlags()
| IOccurrencesFinder.F_READ_OCCURRENCE) == IOccurrencesFinder.F_READ_OCCURRENCE) {
h.setKind(DocumentHighlightKind.Read);
}
int[] loc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset());
int[] endLoc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset() + occurrence.getLength());
h.setRange(new Range(
new Position(loc[0], loc[1]),
new Position(endLoc[0],endLoc[1])
));
return h;
}
示例8: computeDefinitionNavigation
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
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 JDTUtils.toLocation(element);
}
if (element instanceof IMember && ((IMember) element).getClassFile() != null) {
return JDTUtils.toLocation(((IMember) element).getClassFile());
}
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Problem computing definition for" + unit.getElementName(), e);
}
return null;
}
示例9: getLineNumber
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
public static Integer getLineNumber(IMember member) throws JavaModelException {
ITypeRoot typeRoot = member.getTypeRoot();
IBuffer buffer = typeRoot.getBuffer();
if (buffer == null) {
return null;
}
Document document = new Document(buffer.getContents());
int offset = 0;
if (SourceRange.isAvailable(member.getNameRange())) {
offset = member.getNameRange().getOffset();
} else if (SourceRange.isAvailable(member.getSourceRange())) {
offset = member.getSourceRange().getOffset();
}
try {
return document.getLineOfOffset(offset);
} catch (BadLocationException e) {
return null;
}
}
示例10: runAnalysis
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
@Override
public void runAnalysis(IAnalysisReporter reporter, IAnalysisInput input, ITypeRoot compUnit,
CompilationUnit rootNode) {
this.savedReporter = reporter;
this.savedInput = input;
// Save the compilation units to analyze; analyze them later
this.compUnits.add(compUnit);
super.runAnalysis(reporter, input, compUnit, rootNode);
// Must initialize the path on the facade
// In case, we don't run anything!
// XXX. Also, need root class...(less crucial)
if (projectPath == null) {
projectPath = compUnit.getJavaProject().getResource().getLocation().toOSString();
}
}
示例11: run
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
public void run(final String analysis_to_run) {
Crystal crystal = AbstractCrystalPlugin.getCrystalInstance();
crystal.runAnalyses(new IRunCrystalCommand() {
@Override
public IAnalysisReporter reporter() {
return reporter;
}
@Override
public Collection<? extends ITypeRoot> compilationUnits() {
return compilationUnits;
}
@Override
public Set<String> analyses() {
Set<String> hashSet = new HashSet<String>();
hashSet.add(analysis_to_run);
return hashSet;
}
}, null);
}
示例12: getSelectedJavaElement
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
/**
* Determines the Java element the given {@link ITextSelection} points to (i.e. the Java element the cursor is
* positioned to).
*
* @param textSelection
* the {@link ITextSelection} to be checked
* @return the {@link IJavaElement} the cursor is positioned to or {@link Optional#empty()}, if there is no active
* editor, or the active editor is not a Java editor.
*/
public static Optional<IJavaElement> getSelectedJavaElement(final ITextSelection textSelection) {
final Optional<ITypeRoot> javaRootElement = getJavaRootElementOfActiveEditor();
if (javaRootElement.isPresent()) {
try {
final IJavaElement selectedJavaElement = ((ICompilationUnit) javaRootElement.get()).getElementAt(textSelection.getOffset());
if (selectedJavaElement != null) {
return Optional.of(selectedJavaElement);
}
}
catch (final JavaModelException e) {
e.printStackTrace();
}
}
return Optional.empty();
}
示例13: TokenScanner
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
/**
* 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;
}
示例14: create
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
/**
* Creates a new inline method refactoring
*
* @param unit the compilation unit or class file
* @param node the compilation unit node
* @param selectionStart start
* @param selectionLength length
* @return returns the refactoring
*/
public static InlineMethodRefactoring create(
ITypeRoot unit, CompilationUnit node, int selectionStart, int selectionLength) {
ASTNode target =
RefactoringAvailabilityTester.getInlineableMethodNode(
unit, node, selectionStart, selectionLength);
if (target == null) return null;
if (target.getNodeType() == ASTNode.METHOD_DECLARATION) {
return new InlineMethodRefactoring(
unit, (MethodDeclaration) target, selectionStart, selectionLength);
} else {
ICompilationUnit cu = (ICompilationUnit) unit;
if (target.getNodeType() == ASTNode.METHOD_INVOCATION) {
return new InlineMethodRefactoring(
cu, (MethodInvocation) target, selectionStart, selectionLength);
} else if (target.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION) {
return new InlineMethodRefactoring(
cu, (SuperMethodInvocation) target, selectionStart, selectionLength);
} else if (target.getNodeType() == ASTNode.CONSTRUCTOR_INVOCATION) {
return new InlineMethodRefactoring(
cu, (ConstructorInvocation) target, selectionStart, selectionLength);
}
}
return null;
}
示例15: parse
import org.eclipse.jdt.core.ITypeRoot; //导入依赖的package包/类
public CompilationUnit parse(
ITypeRoot typeRoot,
WorkingCopyOwner owner,
boolean resolveBindings,
boolean statementsRecovery,
boolean bindingsRecovery,
IProgressMonitor pm) {
fParser.setResolveBindings(resolveBindings);
fParser.setStatementsRecovery(statementsRecovery);
fParser.setBindingsRecovery(bindingsRecovery);
fParser.setSource(typeRoot);
if (owner != null) fParser.setWorkingCopyOwner(owner);
fParser.setCompilerOptions(getCompilerOptions(typeRoot));
CompilationUnit result = (CompilationUnit) fParser.createAST(pm);
return result;
}