當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleName.getIdentifier方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.SimpleName.getIdentifier方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleName.getIdentifier方法的具體用法?Java SimpleName.getIdentifier怎麽用?Java SimpleName.getIdentifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.SimpleName的用法示例。


在下文中一共展示了SimpleName.getIdentifier方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addStaticImports

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private void addStaticImports(
		Collection<SimpleName> staticReferences,
		ImportRewrite importRewrite,
		UnresolvableImportMatcher unresolvableImportMatcher) {
	for (SimpleName name : staticReferences) {
		IBinding binding= name.resolveBinding();
		if (binding != null) {
			importRewrite.addStaticImport(binding);
		} else {
			// This could be an unresolvable reference to a static member.
			String identifier= name.getIdentifier();
			Set<String> unresolvableImports= unresolvableImportMatcher.matchStaticImports(identifier);
			for (String unresolvableImport : unresolvableImports) {
				int lastDotIndex= unresolvableImport.lastIndexOf('.');
				// It's OK to skip invalid imports.
				if (lastDotIndex != -1) {
					String declaringTypeName= unresolvableImport.substring(0, lastDotIndex);
					String simpleName= unresolvableImport.substring(lastDotIndex + 1);
					// Whether name refers to a field or to a method is unknown.
					boolean isField= false;
					importRewrite.addStaticImport(declaringTypeName, simpleName, isField, UNRESOLVABLE_IMPORT_CONTEXT);
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:27,代碼來源:OrganizeImportsOperation.java

示例2: addEnhancedForWithoutTypeProposals

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode,
		Collection<CUCorrectionProposal> proposals) {
	if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
		ASTNode type= selectedNode.getParent();
		if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
			SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
			if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
				if (svd.getName().getLength() == 0) {
					SimpleName simpleName= (SimpleName) selectedNode;
					String name= simpleName.getIdentifier();
					int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
					String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));

					proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL,
							simpleName, null, relevance));
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:21,代碼來源:UnresolvedElementsSubProcessor.java

示例3: findByProblems

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
	ArrayList<SimpleName> res= new ArrayList<>();

	ASTNode astRoot = parent.getRoot();
	if (!(astRoot instanceof CompilationUnit)) {
		return null;
	}

	IProblem[] problems= ((CompilationUnit) astRoot).getProblems();
	int nameNodeKind= getNameNodeProblemKind(problems, nameNode);
	if (nameNodeKind == 0) { // no problem on node
		return null;
	}

	int bodyStart= parent.getStartPosition();
	int bodyEnd= bodyStart + parent.getLength();

	String name= nameNode.getIdentifier();

	for (int i= 0; i < problems.length; i++) {
		IProblem curr= problems[i];
		int probStart= curr.getSourceStart();
		int probEnd= curr.getSourceEnd() + 1;

		if (probStart > bodyStart && probEnd < bodyEnd) {
			int currKind= getProblemKind(curr);
			if ((nameNodeKind & currKind) != 0) {
				ASTNode node= NodeFinder.perform(parent, probStart, (probEnd - probStart));
				if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
					res.add((SimpleName) node);
				}
			}
		}
	}
	return res.toArray(new SimpleName[res.size()]);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:37,代碼來源:LinkedNodeFinder.java

示例4: add

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
/**
 * Tries to find the given type name and add it to the import structure.
 * @param ref the name node
 */
public void add(SimpleName ref) {
	String typeName= ref.getIdentifier();

	if (fImportsAdded.contains(typeName)) {
		return;
	}

	IBinding binding= ref.resolveBinding();
	if (binding != null) {
		if (binding.getKind() != IBinding.TYPE) {
			return;
		}
		ITypeBinding typeBinding= (ITypeBinding) binding;
		if (typeBinding.isArray()) {
			typeBinding= typeBinding.getElementType();
		}
		typeBinding= typeBinding.getTypeDeclaration();
		if (!typeBinding.isRecovered()) {
			if (needsImport(typeBinding, ref)) {
				fImpStructure.addImport(typeBinding);
				fImportsAdded.add(typeName);
			}
			return;
		}
	} else {
		if (fDoIgnoreLowerCaseNames && typeName.length() > 0) {
			char ch= typeName.charAt(0);
			if (Strings.isLowerCase(ch) && Character.isLetter(ch)) {
				return;
			}
		}
	}

	fImportsAdded.add(typeName);
	fUnresolvedTypes.put(typeName, new UnresolvedTypeData(ref));
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:41,代碼來源:OrganizeImportsOperation.java

示例5: makeString

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
protected static String makeString(SimpleName label) {
	if (label == null) {
		return UNLABELED;
	} else {
		return label.getIdentifier();
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:8,代碼來源:FlowInfo.java

示例6: addNewFieldForType

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private static void addNewFieldForType(ICompilationUnit targetCU, ITypeBinding binding,
		ITypeBinding senderDeclBinding, SimpleName simpleName, boolean isWriteAccess, boolean mustBeConst,
		Collection<CUCorrectionProposal> proposals) {
	String name= simpleName.getIdentifier();
	String nameLabel= BasicElementLabels.getJavaElementName(name);
	String label;
	if (senderDeclBinding.isEnum() && !isWriteAccess) {
		label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createenum_description,
				new Object[] { nameLabel, ASTResolving.getTypeSignature(senderDeclBinding) });
		proposals.add(new NewVariableCorrectionProposal(label, targetCU, NewVariableCorrectionProposal.ENUM_CONST,
				simpleName, senderDeclBinding, 10));
	} else {
		if (!mustBeConst) {
			if (binding == null) {
				label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createfield_description, nameLabel);
			} else {
				label = Messages.format(
						CorrectionMessages.UnresolvedElementsSubProcessor_createfield_other_description,
						new Object[] { nameLabel, ASTResolving.getTypeSignature(senderDeclBinding) });
			}
			int fieldRelevance= StubUtility.hasFieldName(targetCU.getJavaProject(), name) ? IProposalRelevance.CREATE_FIELD_PREFIX_OR_SUFFIX_MATCH : IProposalRelevance.CREATE_FIELD;
			proposals.add(new NewVariableCorrectionProposal(label, targetCU, NewVariableCorrectionProposal.FIELD,
					simpleName, senderDeclBinding, fieldRelevance));
		}

		if (!isWriteAccess && !senderDeclBinding.isAnonymous()) {
			if (binding == null) {
				label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createconst_description, nameLabel);
			} else {
				label = Messages.format(
						CorrectionMessages.UnresolvedElementsSubProcessor_createconst_other_description,
						new Object[] { nameLabel, ASTResolving.getTypeSignature(senderDeclBinding) });
			}
			int constRelevance= StubUtility.hasConstantName(targetCU.getJavaProject(), name) ? IProposalRelevance.CREATE_CONSTANT_PREFIX_OR_SUFFIX_MATCH : IProposalRelevance.CREATE_CONSTANT;
			proposals.add(new NewVariableCorrectionProposal(label, targetCU,
					NewVariableCorrectionProposal.CONST_FIELD, simpleName, senderDeclBinding, constRelevance));
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:40,代碼來源:UnresolvedElementsSubProcessor.java

示例7: addStaticImportFavoriteProposals

import org.eclipse.jdt.core.dom.SimpleName; //導入方法依賴的package包/類
private static void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod,
		Collection<CUCorrectionProposal> proposals) throws JavaModelException {
	IJavaProject project= context.getCompilationUnit().getJavaProject();
	if (JavaModelUtil.is50OrHigher(project)) {
		String pref = PreferenceManager.getPrefs(context.getCompilationUnit().getResource())
				.getFavoriteStaticMembers();
		String[] favourites= pref.split(";"); //$NON-NLS-1$
		if (favourites.length == 0) {
			return;
		}

		CompilationUnit root= context.getASTRoot();
		AST ast= root.getAST();

		String name= node.getIdentifier();
		String[] staticImports= SimilarElementsRequestor.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites);
		for (int i= 0; i < staticImports.length; i++) {
			String curr= staticImports[i];

			ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
			ASTRewrite astRewrite= ASTRewrite.create(ast);

			String label;
			String qualifiedTypeName= Signature.getQualifier(curr);
			String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));

			String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
			int dot= res.lastIndexOf('.');
			if (dot != -1) {
				String usedTypeName= importRewrite.addImport(qualifiedTypeName);
				Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
				astRewrite.replace(node, newName, null);
				label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
			} else {
				label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
			}

			ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label,
					context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT);
			proposal.setImportRewrite(importRewrite);
			proposals.add(proposal);
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:45,代碼來源:UnresolvedElementsSubProcessor.java


注:本文中的org.eclipse.jdt.core.dom.SimpleName.getIdentifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。