本文整理汇总了Java中org.eclipse.jdt.core.ITypeRoot.getJavaProject方法的典型用法代码示例。如果您正苦于以下问题:Java ITypeRoot.getJavaProject方法的具体用法?Java ITypeRoot.getJavaProject怎么用?Java ITypeRoot.getJavaProject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ITypeRoot
的用法示例。
在下文中一共展示了ITypeRoot.getJavaProject方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例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= StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}
示例5: computeFieldConstant
import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
* Compute the textual representation of a 'static' 'final' field's constant initializer value.
*
* @param activePart the part that triggered the computation, or <code>null</code>
* @param selection the selection that references the field, or <code>null</code>
* @param resolvedField the filed whose constant value will be computed
* @param monitor the progress monitor
*
* @return the textual representation of the constant, or <code>null</code> if the
* field is not a constant field, the initializer value could not be computed, or
* the progress monitor was cancelled
* @since 3.4
*/
private String computeFieldConstant(IWorkbenchPart activePart, ISelection selection, IField resolvedField, IProgressMonitor monitor) {
if (!JavadocHover.isStaticFinal(resolvedField))
return null;
Object constantValue;
IJavaProject preferenceProject;
if (selection instanceof ITextSelection && activePart instanceof JavaEditor) {
IEditorPart editor= (IEditorPart) activePart;
ITypeRoot activeType= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
preferenceProject= activeType.getJavaProject();
constantValue= getConstantValueFromActiveEditor(activeType, resolvedField, (ITextSelection) selection, monitor);
if (constantValue == null) // fall back - e.g. when selection is inside Javadoc of the element
constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
} else {
constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
preferenceProject= resolvedField.getJavaProject();
}
if (constantValue != null)
return JavadocHover.getFormattedAssignmentOperator(preferenceProject) + formatCompilerConstantValue(constantValue);
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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:UnresolvedElementsSubProcessor.java
示例7: computeFieldConstant
import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
* Compute the textual representation of a 'static' 'final' field's constant initializer value.
*
* @param activePart the part that triggered the computation, or <code>null</code>
* @param selection the selection that references the field, or <code>null</code>
* @param resolvedField the filed whose constant value will be computed
* @param monitor the progress monitor
*
* @return the textual representation of the constant, or <code>null</code> if the
* field is not a constant field, the initializer value could not be computed, or
* the progress monitor was cancelled
* @since 3.4
*/
private String computeFieldConstant(IWorkbenchPart activePart, ISelection selection, IField resolvedField, IProgressMonitor monitor) {
if (!isStaticFinal(resolvedField))
return null;
Object constantValue;
IJavaProject preferenceProject;
if (selection instanceof ITextSelection && activePart instanceof JavaEditor) {
IEditorPart editor= (IEditorPart) activePart;
ITypeRoot activeType= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
preferenceProject= activeType.getJavaProject();
constantValue= getConstantValueFromActiveEditor(activeType, resolvedField, (ITextSelection) selection, monitor);
if (constantValue == null) // fall back - e.g. when selection is inside Javadoc of the element
constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
} else {
constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
preferenceProject= resolvedField.getJavaProject();
}
if (constantValue != null)
return getFormattedAssignmentOperator(preferenceProject) + formatCompilerConstantValue(constantValue);
return null;
}
示例8: 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;
}
示例9: beforeAllMethods
import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
@Override
// XXX. TODO: Move parts of this code to beforeAllCompUnits()
public void beforeAllMethods(ITypeRoot compUnit, CompilationUnit rootNode) {
savedUnits.add(compUnit);
try {
path = compUnit.getCorrespondingResource().getProject().getLocation();
} catch (JavaModelException ex) {
throw new IllegalStateException("project path not found");
}
// XXX. Why does visiting root expression need to happen before each Compilation unit?
rootNode.accept(new RootExpressionVisitor(types));
// NOTE: we check hierarchy == null so we can initialize this once.
// XXX. Ideally, move this code OUT of beforeAllMethods. Into beforeAllCompilationUnits
// This check is being done for each CompilationUnit
if (hierarchy == null) {
try {
// Choose between simple typeHierarchy and type hierarchy with
// OwnershipDomains
IJavaProject javaProject = compUnit.getJavaProject();
GenHelper.setJavaProject(javaProject);
// Give MiniAst the chance to initialize its type hierarchy
TypeHierarchyFactory.getInstance().registerProject(javaProject);
hierarchy = TypeHierarchyFactory.getInstance().getHierarchy();
// hierarchy = new
// OwnershipDomainsTypeHierarchy(compUnit.getJavaProject());
} catch (JavaModelException e) {
log.log(Level.SEVERE, "Could not set up compilation unit for analysis", e);
}
}
}
示例10: 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 = StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
str =
Strings.changeIndent(
str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}
示例11: 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;
}
示例12: replaceReferences
import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
private RefactoringStatus replaceReferences(ParameterObjectFactory pof, SearchResultGroup group, CompilationUnitRewrite cuRewrite) {
TextEditGroup writeGroup= cuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_replace_write);
TextEditGroup readGroup= cuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_replace_read);
ITypeRoot typeRoot= cuRewrite.getCu();
IJavaProject javaProject= typeRoot.getJavaProject();
AST ast= cuRewrite.getAST();
RefactoringStatus status= new RefactoringStatus();
String parameterName= fDescriptor.getFieldName();
SearchMatch[] searchResults= group.getSearchResults();
for (int j= 0; j < searchResults.length; j++) {
SearchMatch searchMatch= searchResults[j];
ASTNode node= NodeFinder.perform(cuRewrite.getRoot(), searchMatch.getOffset(), searchMatch.getLength());
ASTNode parent= node.getParent();
boolean isDeclaration= parent instanceof VariableDeclaration && ((VariableDeclaration)parent).getInitializer() != node;
if (!isDeclaration && node instanceof SimpleName) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
if (parent.getNodeType() == ASTNode.SWITCH_CASE)
status.addError(RefactoringCoreMessages.ExtractClassRefactoring_error_switch, JavaStatusContext.create(typeRoot, node));
SimpleName name= (SimpleName) node;
ParameterInfo pi= getFieldInfo(name.getIdentifier()).pi;
boolean writeAccess= ASTResolving.isWriteAccess(name);
if (writeAccess && fDescriptor.isCreateGetterSetter()) {
boolean useSuper= parent.getNodeType() == ASTNode.SUPER_FIELD_ACCESS;
Expression qualifier= getQualifier(parent);
ASTNode replaceNode= getReplacementNode(parent, useSuper, qualifier);
Expression assignedValue= getAssignedValue(pof, parameterName, javaProject, status, rewrite, pi, useSuper, name.resolveTypeBinding(), qualifier, replaceNode, typeRoot);
if (assignedValue == null) {
status.addError(RefactoringCoreMessages.ExtractClassRefactoring_error_unable_to_convert_node, JavaStatusContext.create(typeRoot, replaceNode));
} else {
NullLiteral marker= qualifier == null ? null : ast.newNullLiteral();
Expression access= pof.createFieldWriteAccess(pi, parameterName, ast, javaProject, assignedValue, useSuper, marker);
replaceMarker(rewrite, qualifier, access, marker);
rewrite.replace(replaceNode, access, writeGroup);
}
} else {
Expression fieldReadAccess= pof.createFieldReadAccess(pi, parameterName, ast, javaProject, false, null); //qualifier is already there
rewrite.replace(name, fieldReadAccess, readGroup);
}
}
}
return status;
}
示例13: setSource
import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
* Sets the source code to be parsed.
*
* <p>This method automatically sets the project (and compiler options) based on the given
* compilation unit of class file, in a manner equivalent to {@link #setProject(IJavaProject)
* setProject(source.getJavaProject())}.
*
* <p>If the source is a class file without source attachment, the creation of the ast will fail
* with an {@link IllegalStateException}.
*
* <p>This source is not used when the AST is built using {@link #createASTs(ICompilationUnit[],
* String[], ASTRequestor, IProgressMonitor)}.
*
* @param source the Java model compilation unit or class file whose corresponding source code is
* to be parsed, or <code>null</code> if none
* @since 3.3
*/
public void setSource(ITypeRoot source) {
this.typeRoot = source;
// clear the raw source
this.rawSource = null;
if (source != null) {
this.project = source.getJavaProject();
Map options = this.project.getOptions(true);
options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
this.compilerOptions = options;
}
}
示例14: setSource
import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
* Sets the source code to be parsed.
*
* <p>This method automatically sets the project (and compiler
* options) based on the given compilation unit of class file, in a manner
* equivalent to {@link #setProject(IJavaProject) setProject(source.getJavaProject())}.</p>
* <p>If the source is a class file without source attachment, the creation of the
* ast will fail with an {@link IllegalStateException}.</p>
*
* <p>This source is not used when the AST is built using
* {@link #createASTs(ICompilationUnit[], String[], ASTRequestor, IProgressMonitor)}.</p>
*
* @param source the Java model compilation unit or class file whose corresponding source code
* is to be parsed, or <code>null</code> if none
* @since 3.3
*/
public void setSource(ITypeRoot source) {
this.typeRoot = source;
// clear the raw source
this.rawSource = null;
if (source != null) {
this.project = source.getJavaProject();
Map options = this.project.getOptions(true);
options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
this.compilerOptions = options;
}
}