本文整理汇总了Java中org.eclipse.jdt.core.Signature.getQualifier方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.getQualifier方法的具体用法?Java Signature.getQualifier怎么用?Java Signature.getQualifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.Signature
的用法示例。
在下文中一共展示了Signature.getQualifier方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToTestProject
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
public void addToTestProject() throws Exception {
IProject testProject = Util.getWorkspaceRoot().getProject(TEST_PROJECT_NAME);
if (!testProject.exists()) {
throw new Exception("The test project does not exist");
}
IJavaProject javaProject = JavaCore.create(testProject);
IPath srcPath = new Path("/" + TEST_PROJECT_NAME + "/src");
IPackageFragmentRoot pckgRoot = javaProject.findPackageFragmentRoot(srcPath);
String packageName = Signature.getQualifier(typeName);
String cuName = Signature.getSimpleName(typeName) + ".java";
// If the package fragment already exists, this call does nothing
IPackageFragment pckg = pckgRoot.createPackageFragment(packageName, false, null);
cu = pckg.createCompilationUnit(cuName, contents, true, null);
JobsUtilities.waitForIdle();
}
示例2: createCompilationUnit
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Creates an {@link ICompilationUnit} with the given fully qualified name and
* code in the <code>javaProject</code>.
*
* @param javaProject java project to host the new class
* @param fullyQualifiedClassName fully qualified name for the class
* @param source code for the classs
* @return newly created {@link ICompilationUnit}
* @throws JavaModelException
*/
public static ICompilationUnit createCompilationUnit(
IJavaProject javaProject, String fullyQualifiedClassName, String source)
throws JavaModelException {
IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath());
if (root == null) {
addRawClassPathEntry(javaProject,
JavaCore.newSourceEntry(javaProject.getPath()));
root = javaProject.findPackageFragmentRoot(javaProject.getPath());
}
String qualifier = Signature.getQualifier(fullyQualifiedClassName);
IProgressMonitor monitor = new NullProgressMonitor();
IPackageFragment packageFragment = root.createPackageFragment(qualifier,
true, monitor);
String name = Signature.getSimpleName(fullyQualifiedClassName);
return packageFragment.createCompilationUnit(name + ".java", source, false,
monitor);
}
示例3: createCompilationUnit
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Creates an {@link ICompilationUnit} with the given fully qualified name and
* code in the <code>javaProject</code>.
*
* @param javaProject java project to host the new class
* @param fullyQualifiedClassName fully qualified name for the class
* @param source code for the classs
* @return newly created {@link ICompilationUnit}
* @throws JavaModelException
*/
public static ICompilationUnit createCompilationUnit(
IJavaProject javaProject, String fullyQualifiedClassName, String source)
throws JavaModelException {
IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath());
if (root == null) {
addRawClassPathEntry(javaProject,
JavaCore.newSourceEntry(javaProject.getPath()));
root = javaProject.findPackageFragmentRoot(javaProject.getPath());
}
String qualifier = Signature.getQualifier(fullyQualifiedClassName);
IProgressMonitor monitor = new NullProgressMonitor();
IPackageFragment packageFragment = root.createPackageFragment(qualifier,
true, monitor);
String name = Signature.getSimpleName(fullyQualifiedClassName);
ICompilationUnit cu = packageFragment.createCompilationUnit(name + ".java",
source, false, monitor);
JobsUtilities.waitForIdle();
return cu;
}
示例4: findModule
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Finds a particular GWT module by its fully-qualified name.
*
* @param javaProject project in which to search for modules
* @param qualifiedName fully-qualified module name
* @param includeJars indicates whether to include JAR files in search
* @return the module, if found; otherwise <code>null</code>
*/
public static IModule findModule(IJavaProject javaProject, String qualifiedName, final boolean includeJars) {
final String modulePckg = Signature.getQualifier(qualifiedName);
final String simpleName = Signature.getSimpleName(qualifiedName);
return visitFragments(javaProject, includeJars, new IPackageFragmentVisitor<IModule>() {
@Override
public IModule visit(IPackageFragment pckg) throws JavaModelException {
// Look for the package fragment matching the module qualifier
if (modulePckg.equals(pckg.getElementName())) {
for (Object resource : pckg.getNonJavaResources()) {
IModule module = create(resource, includeJars);
// Now compare the resource name to the module name
if (module != null && module.getSimpleName().equals(simpleName)) {
return module;
}
}
}
return null;
}
});
}
示例5: createMethodProposalLabel
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Updates a display label for the given method proposal to item. The display label
* consists of:
* <ul>
* <li>the method name</li>
* <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
* <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
* <li>the raw simple name of the declaring type</li>
* </ul>
* <p>
* Examples:
* For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
* display name is returned: <code>get(int index) Number - List</code>.<br>
* For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
* display name is returned: <code>add(Number o) void - List</code>.<br>
* </p>
*
* @param methodProposal the method proposal to display
* @param item to update
*/
private void createMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) {
StringBuilder description = this.createMethodProposalDescription(methodProposal);
item.setLabel(description.toString());
item.setInsertText(String.valueOf(methodProposal.getName()));
// declaring type
StringBuilder typeInfo = new StringBuilder();
String declaringType= extractDeclaringTypeFQN(methodProposal);
if (methodProposal.getRequiredProposals() != null) {
String qualifier= Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
typeInfo.append(qualifier);
typeInfo.append('.');
}
}
declaringType= Signature.getSimpleName(declaringType);
typeInfo.append(declaringType);
item.setDetail(typeInfo.toString());
setSignature(item, String.valueOf(methodProposal.getSignature()));
setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature()));
setName(item, String.valueOf(methodProposal.getName()));
}
示例6: createLabelWithTypeAndDeclaration
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private void createLabelWithTypeAndDeclaration(CompletionProposal proposal, CompletionItem item) {
char[] name= proposal.getCompletion();
if (!isThisPrefix(name)) {
name= proposal.getName();
}
StringBuilder buf= new StringBuilder();
buf.append(name);
item.setInsertText(buf.toString());
char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
if (typeName.length > 0) {
buf.append(VAR_TYPE_SEPARATOR);
buf.append(typeName);
}
item.setLabel(buf.toString());
char[] declaration= proposal.getDeclarationSignature();
if (declaration != null) {
setDeclarationSignature(item, String.valueOf(declaration));
StringBuilder declBuf = new StringBuilder();
declaration= Signature.getSignatureSimpleName(declaration);
if (declaration.length > 0) {
if (proposal.getRequiredProposals() != null) {
String declaringType= extractDeclaringTypeFQN(proposal);
String qualifier= Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
declBuf.append(qualifier);
declBuf.append('.');
}
}
declBuf.append(declaration);
item.setDetail(declBuf.toString());
}
}
setName(item,String.valueOf(name));
}
示例7: createMethodProposalLabel
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Creates a display label for the given method proposal. The display label consists of:
*
* <ul>
* <li>the method name
* <li>the parameter list (see {@link
* #createParameterList(org.eclipse.jdt.core.CompletionProposal)})
* <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})
* <li>the raw simple name of the declaring type
* </ul>
*
* <p>Examples: For the <code>get(int)</code> method of a variable of type <code>
* List<? extends Number></code>, the following display name is returned: <code>
* get(int index) Number - List</code>.<br>
* For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the
* following display name is returned: <code>add(Number o) void - List</code>.<br>
*
* @param methodProposal the method proposal to display
* @return the display label for the given method proposal
*/
StyledString createMethodProposalLabel(CompletionProposal methodProposal) {
StyledString nameBuffer = new StyledString();
// method name
nameBuffer.append(methodProposal.getName());
// parameters
nameBuffer.append('(');
appendUnboundedParameterList(nameBuffer, methodProposal);
nameBuffer.append(')');
// return type
if (!methodProposal.isConstructor()) {
// TODO remove SignatureUtil.fix83600 call when bugs are fixed
char[] returnType =
createTypeDisplayName(
SignatureUtil.getUpperBound(
Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
nameBuffer.append(RETURN_TYPE_SEPARATOR);
nameBuffer.append(returnType);
}
// declaring type
nameBuffer.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
String declaringType = extractDeclaringTypeFQN(methodProposal);
if (methodProposal.getRequiredProposals() != null) {
String qualifier = Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
nameBuffer.append(qualifier, StyledString.QUALIFIER_STYLER);
nameBuffer.append('.', StyledString.QUALIFIER_STYLER);
}
}
declaringType = Signature.getSimpleName(declaringType);
nameBuffer.append(declaringType, StyledString.QUALIFIER_STYLER);
return Strings.markJavaElementLabelLTR(nameBuffer);
}
示例8: createLabelWithTypeAndDeclaration
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
StyledString createLabelWithTypeAndDeclaration(CompletionProposal proposal) {
char[] name = proposal.getCompletion();
if (!isThisPrefix(name)) name = proposal.getName();
StyledString buf = new StyledString();
buf.append(name);
char[] typeName = Signature.getSignatureSimpleName(proposal.getSignature());
if (typeName.length > 0) {
buf.append(VAR_TYPE_SEPARATOR);
buf.append(typeName);
}
char[] declaration = proposal.getDeclarationSignature();
if (declaration != null) {
declaration = Signature.getSignatureSimpleName(declaration);
if (declaration.length > 0) {
buf.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
if (proposal.getRequiredProposals() != null) {
String declaringType = extractDeclaringTypeFQN(proposal);
String qualifier = Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
buf.append(qualifier, StyledString.QUALIFIER_STYLER);
buf.append('.', StyledString.QUALIFIER_STYLER);
}
}
buf.append(declaration, StyledString.QUALIFIER_STYLER);
}
}
return Strings.markJavaElementLabelLTR(buf);
}
示例9: getText
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
@Override
public String getText(Object element) {
String qualifiedModuleName = (String) element;
String moduleName = Signature.getSimpleName(qualifiedModuleName);
String packageName = Signature.getQualifier(qualifiedModuleName);
return moduleName + " - " + packageName;
}
示例10: validateQualifiedModuleName
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Validates a fully-qualified module name. Module names are validated like fully-qualified Java
* type names; the package should be made up of lower-case segments that are valid Java
* identifiers, and the name should be a camel-cased valid Java identifier.
*
* @param qualifiedName fully-qualified module name
* @return a status object with code <code>IStatus.OK</code> if the given name is valid, otherwise
* a status object indicating what is wrong with the name
*/
public static IStatus validateQualifiedModuleName(String qualifiedName) {
// Validate the module package name according to Java conventions
String pckg = Signature.getQualifier(qualifiedName);
if (!Util.isValidPackageName(pckg)) {
return Util.newErrorStatus("The module package name is invalid");
}
return validateSimpleModuleName(Signature.getSimpleName(qualifiedName));
}
示例11: matches
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
@Override
public boolean matches(String input) {
String packageName = Signature.getQualifier(this.prefixCompareString);
if (!input.toLowerCase().startsWith(packageName.toLowerCase())) {
return false;
}
return super.matches(input);
}
示例12: addStaticImportFavoriteProposals
import org.eclipse.jdt.core.Signature; //导入方法依赖的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);
}
}
}
示例13: addStaticImportFavoriteProposals
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private static void addStaticImportFavoriteProposals(
IInvocationContext context,
SimpleName node,
boolean isMethod,
Collection<ICommandAccess> proposals)
throws JavaModelException {
IJavaProject project = context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref =
PreferenceConstants.getPreference(
PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
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);
}
Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
astRewrite,
IProposalRelevance.ADD_STATIC_IMPORT,
image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
示例14: getPackageName
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
@Override
public String getPackageName() {
return Signature.getQualifier(getQualifiedName());
}