• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ScopeAnalyzer类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer的典型用法代码示例。如果您正苦于以下问题:Java ScopeAnalyzer类的具体用法?Java ScopeAnalyzer怎么用?Java ScopeAnalyzer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ScopeAnalyzer类属于org.eclipse.jdt.internal.corext.dom包,在下文中一共展示了ScopeAnalyzer类的37个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: TypeReferenceProcessor

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
public TypeReferenceProcessor(Set<String> oldSingleImports, Set<String> oldDemandImports, CompilationUnit root, ImportRewrite impStructure, boolean ignoreLowerCaseNames, UnresolvableImportMatcher unresolvableImportMatcher) {
	fOldSingleImports= oldSingleImports;
	fOldDemandImports= oldDemandImports;
	fImpStructure= impStructure;
	fDoIgnoreLowerCaseNames= ignoreLowerCaseNames;
	fUnresolvableImportMatcher= unresolvableImportMatcher;

	ICompilationUnit cu= impStructure.getCompilationUnit();

	fImplicitImports= new HashSet<>(3);
	fImplicitImports.add(""); //$NON-NLS-1$
	fImplicitImports.add("java.lang"); //$NON-NLS-1$
	fImplicitImports.add(cu.getParent().getElementName());

	fAnalyzer= new ScopeAnalyzer(root);

	fCurrPackage= (IPackageFragment) cu.getParent();

	fAllowDefaultPackageImports= cu.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true).equals(JavaCore.VERSION_1_3);

	fImportsAdded= new HashSet<>();
	fUnresolvedTypes= new HashMap<>();
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:24,
代码来源:OrganizeImportsOperation.java

示例2: computeProposals

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
@Override
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);

	org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(root, returnOffset, 0);
	ASTNode varDeclFrag= ASTResolving.findAncestor(finder.getCoveringNode(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
	IVariableBinding varDeclFragBinding= null;
	if (varDeclFrag != null)
		varDeclFragBinding= ((VariableDeclarationFragment) varDeclFrag).resolveBinding();
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		// Bindings are compared to make sure that a lambda does not return a variable which is yet to be initialised.
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr) && !Bindings.equals(curr, varDeclFragBinding)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName());
		}
	}
	return result;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:24,
代码来源:MissingReturnTypeInLambdaCorrectionProposal.java

示例3: evaluateArgumentExpressions

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) {
	CompilationUnit root= (CompilationUnit) fCallerNode.getRoot();

	int offset= fCallerNode.getStartPosition();
	Expression best= null;
	ITypeBinding bestType= null;

	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES);
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		if (type != null && canAssign(type, requiredType) && testModifier(curr)) {
			if (best == null || isMoreSpecific(bestType, type)) {
				best= ast.newSimpleName(curr.getName());
				bestType= type;
			}
		}
	}
	Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, requiredType);
	if (best == null) {
		best= defaultExpression;
	}
	return best;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:26,
代码来源:AddArgumentCorrectionProposal.java

示例4: getExcludedVariableNames

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private String[] getExcludedVariableNames() {
  if (fExcludedVariableNames == null) {
    try {
      IBinding[] bindings =
          new ScopeAnalyzer(fCompilationUnitNode)
              .getDeclarationsInScope(
                  getSelectedExpression().getStartPosition(),
                  ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
      fExcludedVariableNames = new String[bindings.length];
      for (int i = 0; i < bindings.length; i++) {
        fExcludedVariableNames[i] = bindings[i].getName();
      }
    } catch (JavaModelException e) {
      fExcludedVariableNames = new String[0];
    }
  }
  return fExcludedVariableNames;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:19,
代码来源:ExtractTempRefactoring.java

示例5: extractExpressionType

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private static ITypeBinding extractExpressionType(SimpleType variableIdentifier) {
  ScopeAnalyzer analyzer = new ScopeAnalyzer((CompilationUnit) variableIdentifier.getRoot());
  // get the name of the variable to search the type for
  Name name = null;
  if (variableIdentifier.getName() instanceof SimpleName) {
    name = variableIdentifier.getName();
  } else if (variableIdentifier.getName() instanceof QualifiedName) {
    name = ((QualifiedName) variableIdentifier.getName()).getName();
  }

  // analyze variables which are available in the scope at the position of the quick assist
  // invokation
  IBinding[] declarationsInScope =
      analyzer.getDeclarationsInScope(name.getStartPosition(), ScopeAnalyzer.VARIABLES);
  for (int i = 0; i < declarationsInScope.length; i++) {
    IBinding currentVariable = declarationsInScope[i];
    if (((IVariableBinding) currentVariable).getName().equals(name.getFullyQualifiedName())) {
      return ((IVariableBinding) currentVariable).getType();
    }
  }
  return null;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:23,
代码来源:QuickAssistProcessor.java

示例6: getVariableNameProposals

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
/**
 * Retrieves name proposals for a fresh local variable.
 *
 * @param basename the basename of the proposals
 * @param excludedName a name that cannot be used for the variable; <code>null</code> if none
 * @return an array of proposal strings
 */
private String[] getVariableNameProposals(String basename, String excludedName) {
  ASTNode surroundingBlock = fCurrentNode;
  while ((surroundingBlock = surroundingBlock.getParent()) != null) {
    if (surroundingBlock instanceof Block) {
      break;
    }
  }
  Collection<String> localUsedNames =
      new ScopeAnalyzer((CompilationUnit) fCurrentExpression.getRoot())
          .getUsedVariableNames(
              surroundingBlock.getStartPosition(), surroundingBlock.getLength());
  if (excludedName != null) {
    localUsedNames.add(excludedName);
  }
  String[] names =
      StubUtility.getLocalNameSuggestions(
          getCompilationUnit().getJavaProject(),
          basename,
          0,
          localUsedNames.toArray(new String[localUsedNames.size()]));
  return names;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:30,
代码来源:GenerateForLoopAssistProposal.java

示例7: computeProposals

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
protected Expression computeProposals(
    AST ast,
    ITypeBinding returnBinding,
    int returnOffset,
    CompilationUnit root,
    Expression result) {
  ScopeAnalyzer analyzer = new ScopeAnalyzer(root);
  IBinding[] bindings =
      analyzer.getDeclarationsInScope(
          returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
  for (int i = 0; i < bindings.length; i++) {
    IVariableBinding curr = (IVariableBinding) bindings[i];
    ITypeBinding type = curr.getType();
    if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) {
      if (result == null) {
        result = ast.newSimpleName(curr.getName());
      }
      addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
    }
  }
  return result;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:23,
代码来源:MissingReturnTypeCorrectionProposal.java

示例8: computeReservedIdentifiers

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
/**
 * Returns the reserved identifiers in the method to move.
 *
 * @return the reserved identifiers
 * @throws JavaModelException
 *             if the method declaration could not be found
 */
protected String[] computeReservedIdentifiers() throws JavaModelException {
	final List<String> names= new ArrayList<String>();
	final MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode(fMethod, fSourceRewrite.getRoot());
	if (declaration != null) {
		final List<SingleVariableDeclaration> parameters= declaration.parameters();
		VariableDeclaration variable= null;
		for (int index= 0; index < parameters.size(); index++) {
			variable= parameters.get(index);
			names.add(variable.getName().getIdentifier());
		}
		final Block body= declaration.getBody();
		if (body != null) {
			final IBinding[] bindings= new ScopeAnalyzer(fSourceRewrite.getRoot()).getDeclarationsAfter(body.getStartPosition(), ScopeAnalyzer.VARIABLES);
			for (int index= 0; index < bindings.length; index++)
				names.add(bindings[index].getName());
		}
	}
	final String[] result= new String[names.size()];
	names.toArray(result);
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:29,
代码来源:MoveInstanceMethodProcessor.java

示例9: TypeReferenceProcessor

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
public TypeReferenceProcessor(Set<String> oldSingleImports, Set<String> oldDemandImports, CompilationUnit root, ImportRewrite impStructure, boolean ignoreLowerCaseNames) {
	fOldSingleImports= oldSingleImports;
	fOldDemandImports= oldDemandImports;
	fImpStructure= impStructure;
	fDoIgnoreLowerCaseNames= ignoreLowerCaseNames;

	ICompilationUnit cu= impStructure.getCompilationUnit();

	fImplicitImports= new HashSet<String>(3);
	fImplicitImports.add(""); //$NON-NLS-1$
	fImplicitImports.add("java.lang"); //$NON-NLS-1$
	fImplicitImports.add(cu.getParent().getElementName());

	fAnalyzer= new ScopeAnalyzer(root);

	fCurrPackage= (IPackageFragment) cu.getParent();

	fAllowDefaultPackageImports= cu.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true).equals(JavaCore.VERSION_1_3);

	fImportsAdded= new HashSet<String>();
	fUnresolvedTypes= new HashMap<String, UnresolvedTypeData>();
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:23,
代码来源:OrganizeImportsOperation.java

示例10: extractExpressionType

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private static ITypeBinding extractExpressionType(SimpleType variableIdentifier) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer((CompilationUnit) variableIdentifier.getRoot());
	// get the name of the variable to search the type for
	Name name= null;
	if (variableIdentifier.getName() instanceof SimpleName) {
		name= variableIdentifier.getName();
	} else if (variableIdentifier.getName() instanceof QualifiedName) {
		name= ((QualifiedName) variableIdentifier.getName()).getName();
	}

	// analyze variables which are available in the scope at the position of the quick assist invokation
	IBinding[] declarationsInScope= analyzer.getDeclarationsInScope(name.getStartPosition(), ScopeAnalyzer.VARIABLES);
	for (int i= 0; i < declarationsInScope.length; i++) {
		IBinding currentVariable= declarationsInScope[i];
		if (((IVariableBinding) currentVariable).getName().equals(name.getFullyQualifiedName())) {
			return ((IVariableBinding) currentVariable).getType();
		}
	}
	return null;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:21,
代码来源:QuickAssistProcessor.java

示例11: computeProposals

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
@Override
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);

	org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(root, returnOffset, 0);
	ASTNode varDeclFrag= ASTResolving.findAncestor(finder.getCoveringNode(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
	IVariableBinding varDeclFragBinding= null;
	if (varDeclFrag != null)
		varDeclFragBinding= ((VariableDeclarationFragment) varDeclFrag).resolveBinding();
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		// Bindings are compared to make sure that a lambda does not return a variable which is yet to be initialised.
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr) && !Bindings.equals(curr, varDeclFragBinding)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
		}
	}
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:24,
代码来源:MissingReturnTypeInLambdaCorrectionProposal.java

示例12: evaluateReturnExpressions

点赞 3

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private Expression evaluateReturnExpressions(AST ast, ITypeBinding returnBinding, int returnOffset) {
	CompilationUnit root= (CompilationUnit) fMethodDecl.getRoot();

	Expression result= null;
	if (returnBinding != null) {
		ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
		IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY );
		for (int i= 0; i < bindings.length; i++) {
			IVariableBinding curr= (IVariableBinding) bindings[i];
			ITypeBinding type= curr.getType();
			if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) {
				if (result == null) {
					result= ast.newSimpleName(curr.getName());
				}
				addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
			}
		}
	}
	Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, fMethodDecl.getReturnType2(), fMethodDecl.getExtraDimensions());
	addLinkedPositionProposal(RETURN_EXPRESSION_KEY, ASTNodes.asString(defaultExpression), null);
	if (result == null) {
		return defaultExpression;
	}
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion-Juno38,
代码行数:26,
代码来源:MissingReturnTypeCorrectionProposal.java

示例13: hasConflict

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private static boolean hasConflict(int startPosition, IMethodBinding referredMethodBinding, int flags, CompilationUnit cu) {
	ScopeAnalyzer analyzer = new ScopeAnalyzer(cu);
	IBinding[] declarationsInScope = analyzer.getDeclarationsInScope(startPosition, flags);
	for (int i = 0; i < declarationsInScope.length; i++) {
		IBinding decl = declarationsInScope[i];
		if (decl.getName().equals(referredMethodBinding.getName()) && !referredMethodBinding.getMethodDeclaration().isEqualTo(decl)) {
			return true;
		}
	}
	return false;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:12,
代码来源:QuickAssistProcessor.java

示例14: getVisibleLocalVariablesInScope

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
/**
 * Returns a list of local variable names which are visible at the given node.
 *
 * @param node the AST node
 * @return a list of local variable names visible at the given node
 * @see ScopeAnalyzer#getDeclarationsInScope(int, int)
 * @since 3.10
 */
public static List<String> getVisibleLocalVariablesInScope(ASTNode node) {
	List<String> variableNames= new ArrayList<>();
	CompilationUnit root= (CompilationUnit) node.getRoot();
	IBinding[] bindings= new ScopeAnalyzer(root).
			getDeclarationsInScope(node.getStartPosition(), ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
	for (IBinding binding : bindings) {
		if (binding instanceof IVariableBinding && !((IVariableBinding) binding).isField()) {
			variableNames.add(binding.getName());
		}
	}
	return variableNames;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:21,
代码来源:ASTNodes.java

示例15: getDeclarationsInScope

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private IBinding[] getDeclarationsInScope() {
	if (fDeclarationsInScope == null) {
		ScopeAnalyzer analyzer= new ScopeAnalyzer(fCompilationUnit);
		fDeclarationsInScope= analyzer.getDeclarationsInScope(fPosition, ScopeAnalyzer.METHODS | ScopeAnalyzer.TYPES | ScopeAnalyzer.VARIABLES);
	}
	return fDeclarationsInScope;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:8,
代码来源:ContextSensitiveImportRewriteContext.java

示例16: needsImport

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) {
	if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) {
		return false; // no imports for anonymous, local, primitive types or parameters types
	}
	int modifiers= typeBinding.getModifiers();
	if (Modifier.isPrivate(modifiers)) {
		return false; // imports for privates are not required
	}
	ITypeBinding currTypeBinding= Bindings.getBindingOfParentType(ref);
	if (currTypeBinding == null) {
		if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) {
			return true; // reference in package-info.java
		}
		return false; // not in a type
	}
	if (!Modifier.isPublic(modifiers)) {
		if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) {
			return false; // not visible
		}
	}

	ASTNode parent= ref.getParent();
	while (parent instanceof Type) {
		parent= parent.getParent();
	}
	if (parent instanceof AbstractTypeDeclaration && parent.getParent() instanceof CompilationUnit) {
		return true;
	}

	if (typeBinding.isMember()) {
		if (fAnalyzer.isDeclaredInScope(typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY)) {
			return false;
		}
	}
	return true;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:37,
代码来源:OrganizeImportsOperation.java

示例17: computeProposals

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName());
		}
	}
	return result;
}
 

开发者ID:eclipse,
项目名称:eclipse.jdt.ls,
代码行数:16,
代码来源:MissingReturnTypeCorrectionProposal.java

示例18: getDeclarationsInScope

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private IBinding[] getDeclarationsInScope() {
  if (fDeclarationsInScope == null) {
    ScopeAnalyzer analyzer = new ScopeAnalyzer(fCompilationUnit);
    fDeclarationsInScope =
        analyzer.getDeclarationsInScope(
            fPosition, ScopeAnalyzer.METHODS | ScopeAnalyzer.TYPES | ScopeAnalyzer.VARIABLES);
  }
  return fDeclarationsInScope;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:10,
代码来源:ContextSensitiveImportRewriteContext.java

示例19: TypeReferenceProcessor

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
public TypeReferenceProcessor(
    Set<String> oldSingleImports,
    Set<String> oldDemandImports,
    CompilationUnit root,
    ImportRewrite impStructure,
    boolean ignoreLowerCaseNames) {
  fOldSingleImports = oldSingleImports;
  fOldDemandImports = oldDemandImports;
  fImpStructure = impStructure;
  fDoIgnoreLowerCaseNames = ignoreLowerCaseNames;

  ICompilationUnit cu = impStructure.getCompilationUnit();

  fImplicitImports = new HashSet<String>(3);
  fImplicitImports.add(""); // $NON-NLS-1$
  fImplicitImports.add("java.lang"); // $NON-NLS-1$
  fImplicitImports.add(cu.getParent().getElementName());

  fAnalyzer = new ScopeAnalyzer(root);

  fCurrPackage = (IPackageFragment) cu.getParent();

  fAllowDefaultPackageImports =
      cu.getJavaProject()
          .getOption(JavaCore.COMPILER_SOURCE, true)
          .equals(JavaCore.VERSION_1_3);

  fImportsAdded = new HashSet<String>();
  fUnresolvedTypes = new HashMap<String, UnresolvedTypeData>();
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:31,
代码来源:OrganizeImportsOperation.java

示例20: needsImport

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) {
  if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) {
    return false; // no imports for anonymous, local, primitive types or parameters types
  }
  int modifiers = typeBinding.getModifiers();
  if (Modifier.isPrivate(modifiers)) {
    return false; // imports for privates are not required
  }
  ITypeBinding currTypeBinding = Bindings.getBindingOfParentType(ref);
  if (currTypeBinding == null) {
    if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) {
      return true; // reference in package-info.java
    }
    return false; // not in a type
  }
  if (!Modifier.isPublic(modifiers)) {
    if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) {
      return false; // not visible
    }
  }

  ASTNode parent = ref.getParent();
  while (parent instanceof Type) {
    parent = parent.getParent();
  }
  if (parent instanceof AbstractTypeDeclaration
      && parent.getParent() instanceof CompilationUnit) {
    return true;
  }

  if (typeBinding.isMember()) {
    if (fAnalyzer.isDeclaredInScope(
        typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY)) return false;
  }
  return true;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:37,
代码来源:OrganizeImportsOperation.java

示例21: visit

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean visit(final MethodInvocation node) {
  if (!fRemoveMethodQualifiers) return true;

  Expression expression = node.getExpression();
  if (!(expression instanceof ThisExpression)) return true;

  final SimpleName name = node.getName();
  if (name.resolveBinding() == null) return true;

  if (hasConflict(
      expression.getStartPosition(),
      name,
      ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY)) return true;

  Name qualifier = ((ThisExpression) expression).getQualifier();
  if (qualifier != null) {
    ITypeBinding declaringClass = ((IMethodBinding) name.resolveBinding()).getDeclaringClass();
    if (declaringClass == null) return true;

    ITypeBinding caller = getDeclaringType(node);
    if (caller == null) return true;

    ITypeBinding callee = (ITypeBinding) qualifier.resolveBinding();
    if (callee == null) return true;

    if (callee.isAssignmentCompatible(declaringClass)
        && caller.isAssignmentCompatible(declaringClass)) return true;
  }

  fOperations.add(
      new CompilationUnitRewriteOperation() {
        @Override
        public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
            throws CoreException {
          ASTRewrite rewrite = cuRewrite.getASTRewrite();
          TextEditGroup group =
              createTextEditGroup(
                  FixMessages.CodeStyleFix_removeThis_groupDescription, cuRewrite);
          rewrite.remove(node.getExpression(), group);
        }
      });
  return super.visit(node);
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:46,
代码来源:CodeStyleFix.java

示例22: hasConflict

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private boolean hasConflict(int startPosition, SimpleName name, int flag) {
  ScopeAnalyzer analyzer = new ScopeAnalyzer(fCompilationUnit);
  IBinding[] declarationsInScope = analyzer.getDeclarationsInScope(startPosition, flag);
  for (int i = 0; i < declarationsInScope.length; i++) {
    IBinding decl = declarationsInScope[i];
    if (decl.getName().equals(name.getIdentifier()) && name.resolveBinding() != decl)
      return true;
  }
  return false;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:11,
代码来源:CodeStyleFix.java

示例23: getUsedVariableNames

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
protected String[] getUsedVariableNames() {
  final List<String> results = new ArrayList<String>();

  ForStatement forStatement = getForStatement();
  CompilationUnit root = (CompilationUnit) forStatement.getRoot();

  Collection<String> variableNames =
      new ScopeAnalyzer(root)
          .getUsedVariableNames(forStatement.getStartPosition(), forStatement.getLength());
  results.addAll(variableNames);

  forStatement.accept(
      new GenericVisitor() {
        @Override
        public boolean visit(SingleVariableDeclaration node) {
          results.add(node.getName().getIdentifier());
          return super.visit(node);
        }

        @Override
        public boolean visit(VariableDeclarationFragment fragment) {
          results.add(fragment.getName().getIdentifier());
          return super.visit(fragment);
        }
      });

  results.addAll(Arrays.asList(fUsedNames));

  return results.toArray(new String[results.size()]);
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:31,
代码来源:ConvertLoopOperation.java

示例24: getExcludedVariableNames

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private String[] getExcludedVariableNames() {
  if (fExcludedVariableNames == null) {
    try {
      IExpressionFragment expr = getSelectedExpression();
      Collection<String> takenNames =
          new ScopeAnalyzer(fCuRewrite.getRoot())
              .getUsedVariableNames(expr.getStartPosition(), expr.getLength());
      fExcludedVariableNames = takenNames.toArray(new String[takenNames.size()]);
    } catch (JavaModelException e) {
      fExcludedVariableNames = new String[0];
    }
  }
  return fExcludedVariableNames;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:15,
代码来源:ExtractConstantRefactoring.java

示例25: computeProposals

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
@Override
protected Expression computeProposals(
    AST ast,
    ITypeBinding returnBinding,
    int returnOffset,
    CompilationUnit root,
    Expression result) {
  ScopeAnalyzer analyzer = new ScopeAnalyzer(root);
  IBinding[] bindings =
      analyzer.getDeclarationsInScope(
          returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);

  org.eclipse.jdt.core.dom.NodeFinder finder =
      new org.eclipse.jdt.core.dom.NodeFinder(root, returnOffset, 0);
  ASTNode varDeclFrag =
      ASTResolving.findAncestor(finder.getCoveringNode(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
  IVariableBinding varDeclFragBinding = null;
  if (varDeclFrag != null)
    varDeclFragBinding = ((VariableDeclarationFragment) varDeclFrag).resolveBinding();
  for (int i = 0; i < bindings.length; i++) {
    IVariableBinding curr = (IVariableBinding) bindings[i];
    ITypeBinding type = curr.getType();
    // Bindings are compared to make sure that a lambda does not return a variable which is yet to
    // be initialised.
    if (type != null
        && type.isAssignmentCompatible(returnBinding)
        && testModifier(curr)
        && !Bindings.equals(curr, varDeclFragBinding)) {
      if (result == null) {
        result = ast.newSimpleName(curr.getName());
      }
      addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
    }
  }
  return result;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:37,
代码来源:MissingReturnTypeInLambdaCorrectionProposal.java

示例26: evaluateArgumentExpressions

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) {
  CompilationUnit root = (CompilationUnit) fCallerNode.getRoot();

  int offset = fCallerNode.getStartPosition();
  Expression best = null;
  ITypeBinding bestType = null;

  ScopeAnalyzer analyzer = new ScopeAnalyzer(root);
  IBinding[] bindings = analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES);
  for (int i = 0; i < bindings.length; i++) {
    IVariableBinding curr = (IVariableBinding) bindings[i];
    ITypeBinding type = curr.getType();
    if (type != null && canAssign(type, requiredType) && testModifier(curr)) {
      if (best == null || isMoreSpecific(bestType, type)) {
        best = ast.newSimpleName(curr.getName());
        bestType = type;
      }
      addLinkedPositionProposal(key, curr.getName(), null);
    }
  }
  Expression defaultExpression = ASTNodeFactory.newDefaultExpression(ast, requiredType);
  if (best == null) {
    best = defaultExpression;
  }
  addLinkedPositionProposal(key, ASTNodes.asString(defaultExpression), null);
  return best;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:28,
代码来源:AddArgumentCorrectionProposal.java

示例27: proposeLocalName

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
String proposeLocalName(SimpleName fieldName, CompilationUnit root, IJavaProject javaProject) {
  // don't propose names that are already in use:
  Collection<String> variableNames =
      new ScopeAnalyzer(root)
          .getUsedVariableNames(
              this.enclosingMethod.getStartPosition(), this.enclosingMethod.getLength());
  String[] names = new String[variableNames.size() + 1];
  variableNames.toArray(names);
  // don't propose the field name itself, either:
  String identifier = fieldName.getIdentifier();
  names[names.length - 1] = identifier;
  return StubUtility.getLocalNameSuggestions(javaProject, identifier, 0, names)[0];
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:14,
代码来源:ExtractToNullCheckedLocalProposal.java

示例28: initializeExcludedParameterNames

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private void initializeExcludedParameterNames(CompilationUnitRewrite cuRewrite) {
	IBinding[] bindings= new ScopeAnalyzer(cuRewrite.getRoot()).getDeclarationsInScope(
			fSelectedExpression.getStartPosition(), ScopeAnalyzer.VARIABLES);
	fExcludedParameterNames= new String[bindings.length];
	for (int i= 0; i < fExcludedParameterNames.length; i++) {
		fExcludedParameterNames[i]= bindings[i].getName();
	}
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:9,
代码来源:IntroduceParameterRefactoring.java

示例29: getExcludedVariableNames

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private String[] getExcludedVariableNames() {
	if (fExcludedVariableNames == null) {
		try {
			IBinding[] bindings= new ScopeAnalyzer(fCompilationUnitNode).getDeclarationsInScope(getSelectedExpression().getStartPosition(), ScopeAnalyzer.VARIABLES
					| ScopeAnalyzer.CHECK_VISIBILITY);
			fExcludedVariableNames= new String[bindings.length];
			for (int i= 0; i < bindings.length; i++) {
				fExcludedVariableNames[i]= bindings[i].getName();
			}
		} catch (JavaModelException e) {
			fExcludedVariableNames= new String[0];
		}
	}
	return fExcludedVariableNames;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:16,
代码来源:ExtractTempRefactoring.java

示例30: getExcludedVariableNames

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private String[] getExcludedVariableNames() {
	if (fExcludedVariableNames == null) {
		try {
			IExpressionFragment expr= getSelectedExpression();
			Collection<String> takenNames= new ScopeAnalyzer(fCuRewrite.getRoot()).getUsedVariableNames(expr.getStartPosition(), expr.getLength());
			fExcludedVariableNames= takenNames.toArray(new String[takenNames.size()]);
		} catch (JavaModelException e) {
			fExcludedVariableNames= new String[0];
		}
	}
	return fExcludedVariableNames;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:13,
代码来源:ExtractConstantRefactoring.java

示例31: needsImport

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private boolean needsImport(ITypeBinding typeBinding, SimpleName ref) {
	if (!typeBinding.isTopLevel() && !typeBinding.isMember() || typeBinding.isRecovered()) {
		return false; // no imports for anonymous, local, primitive types or parameters types
	}
	int modifiers= typeBinding.getModifiers();
	if (Modifier.isPrivate(modifiers)) {
		return false; // imports for privates are not required
	}
	ITypeBinding currTypeBinding= Bindings.getBindingOfParentType(ref);
	if (currTypeBinding == null) {
		if (ASTNodes.getParent(ref, ASTNode.PACKAGE_DECLARATION) != null) {
			return true; // reference in package-info.java
		}
		return false; // not in a type
	}
	if (!Modifier.isPublic(modifiers)) {
		if (!currTypeBinding.getPackage().getName().equals(typeBinding.getPackage().getName())) {
			return false; // not visible
		}
	}

	ASTNode parent= ref.getParent();
	while (parent instanceof Type) {
		parent= parent.getParent();
	}
	if (parent instanceof AbstractTypeDeclaration && parent.getParent() instanceof CompilationUnit) {
		return true;
	}

	if (typeBinding.isMember()) {
		if (fAnalyzer.isDeclaredInScope(typeBinding, ref, ScopeAnalyzer.TYPES | ScopeAnalyzer.CHECK_VISIBILITY))
			return false;
	}
	return true;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:36,
代码来源:OrganizeImportsOperation.java

示例32: hasConflict

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private boolean hasConflict(int startPosition, SimpleName name, int flag) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(fCompilationUnit);
	IBinding[] declarationsInScope= analyzer.getDeclarationsInScope(startPosition, flag);
	for (int i= 0; i < declarationsInScope.length; i++) {
		IBinding decl= declarationsInScope[i];
		if (decl.getName().equals(name.getIdentifier()) && name.resolveBinding() != decl)
			return true;
	}
	return false;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:11,
代码来源:CodeStyleFix.java

示例33: getUsedVariableNames

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
protected String[] getUsedVariableNames() {
	final List<String> results= new ArrayList<String>();

	ForStatement forStatement= getForStatement();
	CompilationUnit root= (CompilationUnit)forStatement.getRoot();

	Collection<String> variableNames= new ScopeAnalyzer(root).getUsedVariableNames(forStatement.getStartPosition(), forStatement.getLength());
	results.addAll(variableNames);

	forStatement.accept(new GenericVisitor() {
		@Override
		public boolean visit(SingleVariableDeclaration node) {
			results.add(node.getName().getIdentifier());
			return super.visit(node);
		}

		@Override
		public boolean visit(VariableDeclarationFragment fragment) {
			results.add(fragment.getName().getIdentifier());
			return super.visit(fragment);
		}
	});

	results.addAll(Arrays.asList(fUsedNames));

	return results.toArray(new String[results.size()]);
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:28,
代码来源:ConvertLoopOperation.java

示例34: evaluateArgumentExpressions

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) {
	CompilationUnit root= (CompilationUnit) fCallerNode.getRoot();

	int offset= fCallerNode.getStartPosition();
	Expression best= null;
	ITypeBinding bestType= null;

	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES);
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		if (type != null && canAssign(type, requiredType) && testModifier(curr)) {
			if (best == null || isMoreSpecific(bestType, type)) {
				best= ast.newSimpleName(curr.getName());
				bestType= type;
			}
			addLinkedPositionProposal(key, curr.getName(), null);
		}
	}
	Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, requiredType);
	if (best == null) {
		best= defaultExpression;
	}
	addLinkedPositionProposal(key, ASTNodes.asString(defaultExpression), null);
	return best;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:28,
代码来源:AddArgumentCorrectionProposal.java

示例35: getVariableNameProposals

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
/**
 * Retrieves name proposals for a fresh local variable.
 * 
 * @param basename the basename of the proposals
 * @param excludedName a name that cannot be used for the variable; <code>null</code> if none
 * @return an array of proposal strings
 */
private String[] getVariableNameProposals(String basename, String excludedName) {
	ASTNode surroundingBlock= fCurrentNode;
	while ((surroundingBlock= surroundingBlock.getParent()) != null) {
		if (surroundingBlock instanceof Block) {
			break;
		}
	}
	Collection<String> localUsedNames= new ScopeAnalyzer((CompilationUnit) fCurrentExpression.getRoot()).getUsedVariableNames(surroundingBlock.getStartPosition(), surroundingBlock.getLength());
	if (excludedName != null) {
		localUsedNames.add(excludedName);
	}
	String[] names= StubUtility.getLocalNameSuggestions(getCompilationUnit().getJavaProject(), basename, 0, localUsedNames.toArray(new String[localUsedNames.size()]));
	return names;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:22,
代码来源:GenerateForLoopAssistProposal.java

示例36: computeProposals

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null);
		}
	}
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:16,
代码来源:MissingReturnTypeCorrectionProposal.java

示例37: proposeLocalName

点赞 2

import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; //导入依赖的package包/类
String proposeLocalName(SimpleName fieldName, CompilationUnit root, IJavaProject javaProject) {
	// don't propose names that are already in use:
	Collection<String> variableNames= new ScopeAnalyzer(root).getUsedVariableNames(this.enclosingMethod.getStartPosition(), this.enclosingMethod.getLength());
	String[] names = new String[variableNames.size()+1];
	variableNames.toArray(names);
	// don't propose the field name itself, either:
	String identifier= fieldName.getIdentifier();
	names[names.length-1] = identifier;
	return StubUtility.getLocalNameSuggestions(javaProject, identifier, 0, names)[0];
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:11,
代码来源:ExtractToNullCheckedLocalProposal.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)