List of usage examples for org.eclipse.jdt.core Signature toQualifiedName
public static String toQualifiedName(String[] segments)
From source file:at.bestsolution.fxide.jdt.editor.internal.SignatureUtil.java
License:Open Source License
/** * Returns the qualified signature corresponding to * <code>signature</code>.//from ww w . j a va2 s .c om * * @param signature the signature to qualify * @param context the type inside which an unqualified type will be * resolved to find the qualifier, or <code>null</code> if no * context is available * @return the qualified signature */ public static String qualifySignature(final String signature, final IType context) { if (context == null) return signature; String qualifier = Signature.getSignatureQualifier(signature); if (qualifier.length() > 0) return signature; String elementType = Signature.getElementType(signature); String erasure = Signature.getTypeErasure(elementType); String simpleName = Signature.getSignatureSimpleName(erasure); String genericSimpleName = Signature.getSignatureSimpleName(elementType); int dim = Signature.getArrayCount(signature); try { String[][] strings = context.resolveType(simpleName); if (strings != null && strings.length > 0) qualifier = strings[0][0]; } catch (JavaModelException e) { // ignore - not found } if (qualifier.length() == 0) return signature; String qualifiedType = Signature.toQualifiedName(new String[] { qualifier, genericSimpleName }); String qualifiedSignature = Signature.createTypeSignature(qualifiedType, true); String newSignature = Signature.createArraySignature(qualifiedSignature, dim); return newSignature; }
From source file:com.google.gwt.eclipse.core.search.JavaRefIndex.java
License:Open Source License
/** * Returns all classes referenced by this Java ref. This includes the specific * type specified in the reference, as well as all declaring types. For * example, if the ref's className() is 'com.google.A.B.C', this will return * the array: [ com.google.A.B.C, com.google.A.B, com.google.A ] *///from ww w. jav a2 s. c om private String[] getClassNames(IIndexedJavaRef ref) { String innermostClassName = ref.className().replace('$', '.'); List<String> segments = Arrays.asList(Signature.getSimpleNames(innermostClassName)); List<String> classNames = new ArrayList<String>(); // Build the list of class names from innermost to outermost for (int i = segments.size() - 1; i >= 0; i--) { // If we hit a lower-case segment, assume it's a package fragment, which // means there are no remaining outer types to add to the index if (Character.isLowerCase(segments.get(i).charAt(0))) { break; } // Add the current class name (fully-qualified) to the list String[] classSegments = segments.subList(0, i + 1).toArray(new String[0]); String className = Signature.toQualifiedName(classSegments); classNames.add(className); } return classNames.toArray(new String[0]); }
From source file:org.eclipse.objectteams.otdt.debug.ui.internal.actions.OTToggleBreakpointAdapter.java
License:Open Source License
/** * Returns the resolved type signature for the given signature in the given * method, or <code>null</code> if unable to resolve. * /*from ww w. j av a2s . c om*/ * @param method method containing the type signature * @param typeSignature the type signature to resolve * @return the resolved type signature * @throws JavaModelException */ private static String resolveTypeSignature(IMethod method, String typeSignature) throws JavaModelException { int count = Signature.getArrayCount(typeSignature); String elementTypeSignature = Signature.getElementType(typeSignature); if (elementTypeSignature.length() == 1) { // no need to resolve primitive types return typeSignature; } String elementTypeName = Signature.toString(elementTypeSignature); IType type = method.getDeclaringType(); String[][] resolvedElementTypeNames = type.resolveType(elementTypeName); if (resolvedElementTypeNames == null || resolvedElementTypeNames.length != 1) { // check if type parameter ITypeParameter typeParameter = method.getTypeParameter(elementTypeName); if (!typeParameter.exists()) { typeParameter = type.getTypeParameter(elementTypeName); } if (typeParameter.exists()) { String[] bounds = typeParameter.getBounds(); if (bounds.length == 0) { return "Ljava/lang/Object;"; //$NON-NLS-1$ } String bound = Signature.createTypeSignature(bounds[0], false); return Signature.createArraySignature(resolveTypeSignature(method, bound), count); } // the type name cannot be resolved return null; } String[] types = resolvedElementTypeNames[0]; types[1] = types[1].replace('.', '$'); String resolvedElementTypeName = Signature.toQualifiedName(types); String resolvedElementTypeSignature = EMPTY_STRING; if (types[0].equals(EMPTY_STRING)) { resolvedElementTypeName = resolvedElementTypeName.substring(1); resolvedElementTypeSignature = Signature.createTypeSignature(resolvedElementTypeName, true); } else { resolvedElementTypeSignature = Signature.createTypeSignature(resolvedElementTypeName, true).replace('.', '/'); } return Signature.createArraySignature(resolvedElementTypeSignature, count); }
From source file:org.eclipse.stardust.modeling.validation.util.TypeFinder.java
License:Open Source License
public static String resolveName(IType type, String signature) throws JavaModelException { String typeName = null;/*from w w w. j a v a 2 s .c om*/ int arrayCount = Signature.getArrayCount(signature); // todo: this does not take into account generics !!! if (signature.charAt(arrayCount) == Signature.C_UNRESOLVED) { String[][] resolved = type.resolveType(Signature.toString(signature)); if (resolved.length == 0) { warn(Validation_Messages.MSG_UnableToResolve + Signature.toString(signature)); } else if (resolved.length > 1) { warn(Validation_Messages.MSG_AmbiguousDeclaration + Signature.toString(signature)); } else { typeName = Signature.toQualifiedName(resolved[0]); } } else { typeName = Signature.toString(signature); } return typeName; }
From source file:org.eclipseguru.gwt.core.internal.codegen.AsyncServiceCodeGenerator.java
License:Open Source License
/** * Add all methods from the given interface and its super interfaces to the * given list./*from w w w . j a v a 2 s. c o m*/ * * @param type * Interface to get the methods of * @param output * List to add the methods to * @throws CoreException * If an error occurs */ private static void collectAllInterfaceAndSuperMethods(final IType type, final List<IMethod> output, final Set<String> methodSigs) throws CoreException { for (final IMethod method : type.getMethods()) { // Don't repeat the same method final String methodSig = method.getElementName() + method.getSignature(); if (!methodSigs.add(methodSig)) { continue; } output.add(method); } for (final String superInterfaceName : type.getSuperInterfaceNames()) { final String[][] resolvedType = type.resolveType(superInterfaceName); if (resolvedType != null) { for (final String[] typeSegments : resolvedType) { final IType superInterface = type.getJavaProject() .findType(Signature.toQualifiedName(typeSegments)); if (superInterface != null) { collectAllInterfaceAndSuperMethods(superInterface, output, methodSigs); } } } } }
From source file:org.eclipseguru.gwt.core.internal.codegen.AsyncServiceCodeGenerator.java
License:Open Source License
/** * Collects imports including imports from super-interfaces of the specified * type./*from w ww. ja v a 2s.c om*/ * * @param type * @param imports * @throws JavaModelException */ private static void collectImports(final IType type, final ImportsManager imports) throws JavaModelException { final ICompilationUnit compilationUnit = type.getCompilationUnit(); if (compilationUnit != null) { final IImportDeclaration[] existingImports = compilationUnit.getImports(); for (final IImportDeclaration declaration : existingImports) { if (Flags.isStatic(declaration.getFlags())) { String name = Signature.getSimpleName(declaration.getElementName()); final boolean isField = !name.endsWith("()"); //$NON-NLS-1$ if (!isField) { name = name.substring(0, name.length() - 2); } final String qualifier = Signature.getQualifier(declaration.getElementName()); imports.addStaticImport(qualifier, name, isField); } else { imports.addImport(declaration.getElementName()); } } } for (final String superInterfaceName : type.getSuperInterfaceNames()) { final String[][] resolvedType = type.resolveType(superInterfaceName); if (resolvedType != null) { for (final String[] typeSegments : resolvedType) { final IType superInterface = type.getJavaProject() .findType(Signature.toQualifiedName(typeSegments)); if (superInterface != null) { collectImports(superInterface, imports); } } } } }
From source file:org.entirej.framework.plugin.framework.properties.EJPluginBlockProperties.java
License:Apache License
public List<EJPluginBlockItemProperties> getServiceItems() { List<EJPluginBlockItemProperties> newItems = new ArrayList<EJPluginBlockItemProperties>(); try {// w w w. j a v a 2 s .c om IType serviceType = getEntireJProperties().getJavaProject().findType(_serviceClassName); if (serviceType != null) { String[] superInterfaces = serviceType.getSuperInterfaceTypeSignatures(); for (String superInterface : superInterfaces) { String typeErasure = Signature.getTypeErasure(Signature.toString(superInterface)); if (typeErasure != null && EJBlockService.class.getSimpleName().equals(typeErasure)) { String[] typeArguments = Signature.getTypeArguments(superInterface); if (typeArguments.length == 1) { serviceType.getTypeParameter(Signature.toString(typeArguments[0])).getPath(); String[][] resolveType = serviceType.resolveType(Signature.toString(typeArguments[0])); if (resolveType != null && resolveType.length == 1) { String[] typeSegments = resolveType[0]; String pojoName = Signature.toQualifiedName(typeSegments); IType pojoType = getEntireJProperties().getJavaProject().findType(pojoName); if (pojoType != null) { IMethod[] methods = pojoType.getMethods(); for (IMethod method : methods) { if (!method.isConstructor() && method.getNumberOfParameters() == 0 && (!Signature.SIG_VOID.equals(method.getReturnType()))) { String name = method.getElementName(); if (name.startsWith("get")) { name = name.substring(3); } else if (name.startsWith("is")) { name = name.substring(2); } else { continue; } // check dose it Has setter name IMethod setter = pojoType.getMethod(String.format("set%s", name), new String[] { method.getReturnType() }); if (setter != null && setter.exists()) { String fieldName = String.format("%s%s", name.substring(0, 1).toLowerCase(), name.substring(1)); EJPluginBlockItemProperties item = new EJPluginBlockItemProperties( this, false); item.setName(fieldName); String[][] resolveRetrunType = pojoType .resolveType(Signature.toString(method.getReturnType())); if (resolveRetrunType != null && resolveRetrunType.length == 1) { item.setDataTypeClassName( Signature.toQualifiedName(resolveRetrunType[0])); } item.setBlockServiceItem(true); item.setMandatoryItem(false); newItems.add(item); } } } } } } } } } } catch (JavaModelException e) { EJCoreLog.logException(e); } finally { } return newItems; }
From source file:org.hibernate.eclipse.mapper.extractor.HBMInfoExtractor.java
License:Open Source License
public String getNearestType(IJavaProject project, Node parentNode) { String typename = getNearestType(parentNode); if (typename != null) return typename; try {/*from w w w .j a v a 2s. co m*/ if ("component".equals(parentNode.getNodeName())) { // probably need to integrate this into extractor? //$NON-NLS-1$ Node componentPropertyNodeName = parentNode.getAttributes().getNamedItem("name"); //$NON-NLS-1$ if (componentPropertyNodeName != null) { String parentTypeName = getNearestType(project, parentNode.getParentNode()); if (parentTypeName != null) { String componentName = componentPropertyNodeName.getNodeValue(); IType parentType = project.findType(parentTypeName); if (parentType != null) { // check to avoid null pointer exception IField field = parentType.getField(componentName); if (field.exists()) { String fieldTypeSignature = field.getTypeSignature(); String qualifier = Signature.getSignatureQualifier(fieldTypeSignature); String simpleName = Signature.getSignatureSimpleName(fieldTypeSignature); if (!StringHelper.isEmpty(qualifier)) { simpleName = Signature.toQualifiedName(new String[] { qualifier, simpleName }); } String[][] possibleTypes = null; possibleTypes = parentType.resolveType(simpleName); if (possibleTypes != null && possibleTypes.length > 0) { typename = Signature.toQualifiedName(possibleTypes[0]); } } } } } } } catch (JavaModelException jme) { // ignore, reset typename for safety typename = null; } return typename; }
From source file:org.sonatype.m2e.plexus.annotations.internal.JDTComponentGleaner.java
License:Open Source License
public ComponentDescriptor glean(IType type, IProgressMonitor monitor) throws JavaModelException { IAnnotation compAnn = getAnnotation(type, type, "Component"); if (compAnn == null) { return null; // not a component }//from ww w. ja va 2 s .c o m ComponentDescriptor component = new ComponentDescriptor(); Map<String, IMemberValuePair> annMembers = getMembersMap(compAnn); IMemberValuePair roleMember = annMembers.get("role"); String[][] role = type.resolveType((String) roleMember.getValue()); if (role != null) { // JDT model is out of sync? component.setRole(Signature.toQualifiedName(role[0])); } component.setRoleHint(getStringValue(type, annMembers.get("hint"), monitor)); component.setImplementation(type.getFullyQualifiedName()); component.setVersion(getStringValue(type, annMembers.get("version"), monitor)); component.setComponentType(getStringValue(type, annMembers.get("type"), monitor)); component.setInstantiationStrategy(getStringValue(type, annMembers.get("instantiationStrategy"), monitor)); component.setLifecycleHandler(getStringValue(type, annMembers.get("lifecycleHandler"), monitor)); component.setComponentProfile(getStringValue(type, annMembers.get("profile"), monitor)); component.setComponentComposer(getStringValue(type, annMembers.get("composer"), monitor)); component.setComponentConfigurator(getStringValue(type, annMembers.get("configurator"), monitor)); component.setComponentFactory(getStringValue(type, annMembers.get("factory"), monitor)); component.setDescription(getStringValue(type, annMembers.get("description"), monitor)); component.setAlias(getStringValue(type, annMembers.get("alias"), monitor)); component.setIsolatedRealm(getBooleanValue(annMembers.get("isolatedRealm"))); for (IField field : getFields(type, monitor)) { ComponentRequirement requirement = findRequirement(field, monitor); if (requirement != null) { component.addRequirement(requirement); } PlexusConfiguration config = findConfiguration(field); if (config != null) { addChildConfiguration(component, config); } } return component; }
From source file:org.sonatype.m2e.plexus.annotations.internal.JDTComponentGleaner.java
License:Open Source License
private ComponentRequirement findRequirement(IField field, IProgressMonitor monitor) throws JavaModelException { IJavaProject javaProject = field.getJavaProject(); IType declaringType = field.getDeclaringType(); IAnnotation anno = getAnnotation(declaringType, field, "Requirement"); if (anno == null) { return null; }// ww w . ja v a 2 s .co m Map<String, IMemberValuePair> annMembers = getMembersMap(anno); IType fieldType = resolve(declaringType, Signature.toString(field.getTypeSignature())); if (fieldType == null) { // XXX why is this? return null; } ComponentRequirement requirement; if (isRequirementListType(fieldType, monitor)) { requirement = new ComponentRequirementList(); String[] hints = null; IMemberValuePair member = annMembers.get("hints"); if (member != null) { Object[] os = (Object[]) member.getValue(); hints = new String[os.length]; for (int i = 0; i < os.length; i++) { hints[i] = (String) os[i]; } } if (hints != null && hints.length > 0) { ((ComponentRequirementList) requirement).setRoleHints(Arrays.asList(hints)); } } else { requirement = new ComponentRequirement(); requirement.setRoleHint(getStringValue(declaringType, annMembers.get("hint"), monitor)); } String role = null; IMemberValuePair roleMember = annMembers.get("role"); if (roleMember != null) { String fqnRole = Signature .toQualifiedName(declaringType.resolveType((String) roleMember.getValue())[0]); if (!"java.lang.Object".equals(fqnRole)) { role = javaProject.findType(fqnRole).getFullyQualifiedName(); } } if (role == null) { role = fieldType.getFullyQualifiedName(); } requirement.setRole(role); requirement.setFieldName(field.getElementName()); requirement.setFieldMappingType(fieldType.getFullyQualifiedName()); IMemberValuePair optionalMember = annMembers.get("optional"); if (optionalMember != null) { requirement.setOptional(getBooleanValue(optionalMember)); } return requirement; }