List of usage examples for org.eclipse.jdt.core ITypeParameter getElementName
String getElementName();
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private Substitutions getMethodSubstitions(IMethod method) throws JavaModelException { if (fMethodSubstitutions == null) { fMethodSubstitutions = new LRUMap<>(3); }//from ww w. j a v a 2 s .c o m Substitutions s = fMethodSubstitutions.get(method); if (s == null) { ITypeParameter[] typeParameters = method.getTypeParameters(); if (typeParameters.length == 0) { s = Substitutions.EMPTY_SUBST; } else { IType instantiatedType = method.getDeclaringType(); s = new Substitutions(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter curr = typeParameters[i]; s.addSubstitution(curr.getElementName(), '+' + String.valueOf(i), getTypeParameterErasure(curr, instantiatedType)); } } fMethodSubstitutions.put(method, s); } return s; }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private void computeSubstitutions(IType instantiatedType, IType instantiatingType, String[] typeArguments) throws JavaModelException { Substitutions s = new Substitutions(); fTypeVariableSubstitutions.put(instantiatedType, s); ITypeParameter[] typeParameters = instantiatedType.getTypeParameters(); if (instantiatingType == null) { // the focus type for (int i = 0; i < typeParameters.length; i++) { ITypeParameter curr = typeParameters[i]; // use star to make type variables different from type refs s.addSubstitution(curr.getElementName(), '*' + curr.getElementName(), getTypeParameterErasure(curr, instantiatedType)); }// w w w.j av a 2 s. c om } else { if (typeParameters.length == typeArguments.length) { for (int i = 0; i < typeParameters.length; i++) { ITypeParameter curr = typeParameters[i]; String substString = getSubstitutedTypeName(typeArguments[i], instantiatingType); // substitute in the context of the instantiatingType String erasure = getErasedTypeName(typeArguments[i], instantiatingType); // get the erasure from the type argument s.addSubstitution(curr.getElementName(), substString, erasure); } } else if (typeArguments.length == 0) { // raw type reference for (int i = 0; i < typeParameters.length; i++) { ITypeParameter curr = typeParameters[i]; String erasure = getTypeParameterErasure(curr, instantiatedType); s.addSubstitution(curr.getElementName(), erasure, erasure); } } else { // code with errors } } String superclassTypeSignature = instantiatedType.getSuperclassTypeSignature(); if (superclassTypeSignature != null) { String[] superTypeArguments = Signature.getTypeArguments(superclassTypeSignature); IType superclass = fHierarchy.getSuperclass(instantiatedType); if (superclass != null && !fTypeVariableSubstitutions.containsKey(superclass)) { computeSubstitutions(superclass, instantiatedType, superTypeArguments); } } String[] superInterfacesTypeSignature; if (instantiatedType.isAnonymous()) { // special case: superinterface is also returned by IType#getSuperclassTypeSignature() superInterfacesTypeSignature = new String[] { superclassTypeSignature }; } else { superInterfacesTypeSignature = instantiatedType.getSuperInterfaceTypeSignatures(); } int nInterfaces = superInterfacesTypeSignature.length; if (nInterfaces > 0) { IType[] superInterfaces = fHierarchy.getSuperInterfaces(instantiatedType); if (superInterfaces.length == nInterfaces) { for (int i = 0; i < nInterfaces; i++) { String[] superTypeArguments = Signature.getTypeArguments(superInterfacesTypeSignature[i]); IType superInterface = superInterfaces[i]; if (!fTypeVariableSubstitutions.containsKey(superInterface)) { computeSubstitutions(superInterface, instantiatedType, superTypeArguments); } } } } }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private List<String> initTypeParameterNames() { if (fMethod != null) { try {/*from w ww . j av a2s . c o m*/ ArrayList<String> typeParameterNames = new ArrayList<>(); for (ITypeParameter typeParameter : fMethod.getTypeParameters()) { typeParameterNames.add(typeParameter.getElementName()); } return typeParameterNames; } catch (JavaModelException e) { //TODO e.printStackTrace(); } } return Collections.emptyList(); }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Handle {@inheritDoc}.//from w w w . ja va2s .co m * * @param node the node * @return <code>true</code> iff the node was an {@inheritDoc} node and has been handled */ private boolean handleInheritDoc(TagElement node) { if (!TagElement.TAG_INHERITDOC.equals(node.getTagName())) return false; try { if (fMethod == null) return false; TagElement blockTag = (TagElement) node.getParent(); String blockTagName = blockTag.getTagName(); if (blockTagName == null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_PARAM.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); int size = fragments.size(); if (size > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); String[] parameterNames = fMethod.getParameterNames(); for (int i = 0; i < parameterNames.length; i++) { if (name.equals(parameterNames[i])) { CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i); return handleInherited(inherited); } } } else if (size > 2 && first instanceof TextElement) { String firstText = ((TextElement) first).getText(); if ("<".equals(firstText)) { //$NON-NLS-1$ Object second = fragments.get(1); Object third = fragments.get(2); if (second instanceof SimpleName && third instanceof TextElement) { String thirdText = ((TextElement) third).getText(); if (">".equals(thirdText)) { //$NON-NLS-1$ String name = ((SimpleName) second).getIdentifier(); ITypeParameter[] typeParameters = fMethod.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (name.equals(typeParameter.getElementName())) { CharSequence inherited = fJavadocLookup .getInheritedTypeParamDescription(fMethod, i); return handleInherited(inherited); } } } } } } } } else if (TagElement.TAG_RETURN.equals(blockTagName)) { CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_THROWS.equals(blockTagName) || TagElement.TAG_EXCEPTION.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name); return handleInherited(inherited); } } } } catch (JavaModelException e) { //TODO e.printStackTrace(); } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java
License:Open Source License
private AbstractMethodDeclaration convert(IMethod method, IType type) throws JavaModelException { AbstractMethodDeclaration methodDeclaration; org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = null; // convert 1.5 specific constructs only if compliance is 1.5 or above if (this.has1_5Compliance) { /* convert type parameters */ ITypeParameter[] typeParameters = method.getTypeParameters(); if (typeParameters != null && typeParameters.length > 0) { int parameterCount = typeParameters.length; typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount]; for (int i = 0; i < parameterCount; i++) { ITypeParameter typeParameter = typeParameters[i]; typeParams[i] = createTypeParameter(typeParameter.getElementName().toCharArray(), stringArrayToCharArray(typeParameter.getBounds()), 0, 0); }/*ww w . j av a 2 s .c o m*/ } } if (method.isConstructor()) { ConstructorDeclaration decl = new ConstructorDeclaration(this.compilationResult); decl.bits &= ~ASTNode.IsDefaultConstructor; decl.typeParameters = typeParams; methodDeclaration = decl; } else { MethodDeclaration decl = type.isAnnotation() ? new AnnotationMethodDeclaration(this.compilationResult) : new MethodDeclaration(this.compilationResult); /* convert return type */ TypeReference typeReference = createTypeReference(method.getReturnType()); if (typeReference == null) return null; decl.returnType = typeReference; decl.typeParameters = typeParams; methodDeclaration = decl; } methodDeclaration.selector = method.getElementName().toCharArray(); int flags = method.getFlags(); boolean isVarargs = Flags.isVarargs(flags); methodDeclaration.modifiers = flags & ~Flags.AccVarargs; /* convert arguments */ String[] argumentTypeNames = method.getParameterTypes(); String[] argumentNames = method.getParameterNames(); int argumentCount = argumentTypeNames == null ? 0 : argumentTypeNames.length; // Ignore synthetic arguments (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212224) int startIndex = (method.isConstructor() && type.isMember() && !Flags.isStatic(type.getFlags())) ? 1 : 0; argumentCount -= startIndex; methodDeclaration.arguments = new Argument[argumentCount]; for (int i = 0; i < argumentCount; i++) { String argumentTypeName = argumentTypeNames[startIndex + i]; TypeReference typeReference = createTypeReference(argumentTypeName); if (typeReference == null) return null; if (isVarargs && i == argumentCount - 1) { typeReference.bits |= ASTNode.IsVarArgs; } methodDeclaration.arguments[i] = new Argument(argumentNames[i].toCharArray(), 0, typeReference, ClassFileConstants.AccDefault); // do not care whether was final or not } /* convert thrown exceptions */ String[] exceptionTypeNames = method.getExceptionTypes(); int exceptionCount = exceptionTypeNames == null ? 0 : exceptionTypeNames.length; if (exceptionCount > 0) { methodDeclaration.thrownExceptions = new TypeReference[exceptionCount]; for (int i = 0; i < exceptionCount; i++) { TypeReference typeReference = createTypeReference(exceptionTypeNames[i]); if (typeReference == null) return null; methodDeclaration.thrownExceptions[i] = typeReference; } } return methodDeclaration; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java
License:Open Source License
private TypeDeclaration convert(IType type, IType alreadyComputedMember, TypeDeclaration alreadyComputedMemberDeclaration) throws JavaModelException { /* create type declaration - can be member type */ TypeDeclaration typeDeclaration = new TypeDeclaration(this.compilationResult); if (type.getDeclaringType() != null) { typeDeclaration.bits |= ASTNode.IsMemberType; }//from w w w . ja v a 2 s . co m typeDeclaration.name = type.getElementName().toCharArray(); typeDeclaration.modifiers = type.getFlags(); /* set superclass and superinterfaces */ if (type.getSuperclassName() != null) { TypeReference typeReference = createTypeReference(type.getSuperclassTypeSignature()); if (typeReference != null) { typeDeclaration.superclass = typeReference; typeDeclaration.superclass.bits |= ASTNode.IsSuperType; } } String[] interfaceTypes = type.getSuperInterfaceTypeSignatures(); int interfaceCount = interfaceTypes == null ? 0 : interfaceTypes.length; typeDeclaration.superInterfaces = new TypeReference[interfaceCount]; int count = 0; for (int i = 0; i < interfaceCount; i++) { TypeReference typeReference = createTypeReference(interfaceTypes[i]); if (typeReference != null) { typeDeclaration.superInterfaces[count] = typeReference; typeDeclaration.superInterfaces[count++].bits |= ASTNode.IsSuperType; } } if (count != interfaceCount) { System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.superInterfaces = new TypeReference[interfaceCount], 0, interfaceCount); } // convert 1.5 specific constructs only if compliance is 1.5 or above if (this.has1_5Compliance) { /* convert type parameters */ ITypeParameter[] typeParameters = type.getTypeParameters(); if (typeParameters != null && typeParameters.length > 0) { int parameterCount = typeParameters.length; org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParams = new org.eclipse.jdt.internal.compiler.ast.TypeParameter[parameterCount]; for (int i = 0; i < parameterCount; i++) { ITypeParameter typeParameter = typeParameters[i]; typeParams[i] = createTypeParameter(typeParameter.getElementName().toCharArray(), stringArrayToCharArray(typeParameter.getBounds()), 0, 0); } typeDeclaration.typeParameters = typeParams; } } /* convert member types */ IType[] memberTypes = type.getTypes(); int memberTypeCount = memberTypes == null ? 0 : memberTypes.length; typeDeclaration.memberTypes = new TypeDeclaration[memberTypeCount]; for (int i = 0; i < memberTypeCount; i++) { if (alreadyComputedMember != null && alreadyComputedMember.getFullyQualifiedName() .equals(memberTypes[i].getFullyQualifiedName())) { typeDeclaration.memberTypes[i] = alreadyComputedMemberDeclaration; } else { typeDeclaration.memberTypes[i] = convert(memberTypes[i], null, null); } typeDeclaration.memberTypes[i].enclosingType = typeDeclaration; } /* convert fields */ IField[] fields = type.getFields(); int fieldCount = fields == null ? 0 : fields.length; typeDeclaration.fields = new FieldDeclaration[fieldCount]; count = 0; for (int i = 0; i < fieldCount; i++) { FieldDeclaration fieldDeclaration = convert(fields[i], type); if (fieldDeclaration != null) { typeDeclaration.fields[count++] = fieldDeclaration; } } if (count != fieldCount) { System.arraycopy(typeDeclaration.fields, 0, typeDeclaration.fields = new FieldDeclaration[count], 0, count); } /* convert methods - need to add default constructor if necessary */ IMethod[] methods = type.getMethods(); int methodCount = methods == null ? 0 : methods.length; /* source type has a constructor ? */ /* by default, we assume that one is needed. */ int neededCount = 1; for (int i = 0; i < methodCount; i++) { if (methods[i].isConstructor()) { neededCount = 0; // Does not need the extra constructor since one constructor already exists. break; } } boolean isInterface = type.isInterface(); neededCount = isInterface ? 0 : neededCount; typeDeclaration.methods = new AbstractMethodDeclaration[methodCount + neededCount]; if (neededCount != 0) { // add default constructor in first position typeDeclaration.methods[0] = typeDeclaration.createDefaultConstructor(false, false); } boolean hasAbstractMethods = false; count = 0; for (int i = 0; i < methodCount; i++) { AbstractMethodDeclaration method = convert(methods[i], type); if (method != null) { boolean isAbstract; if ((isAbstract = method.isAbstract()) || isInterface) { // fix-up flag method.modifiers |= ExtraCompilerModifiers.AccSemicolonBody; } if (isAbstract) { hasAbstractMethods = true; } typeDeclaration.methods[neededCount + (count++)] = method; } } if (count != methodCount) { System.arraycopy(typeDeclaration.methods, 0, typeDeclaration.methods = new AbstractMethodDeclaration[count + neededCount], 0, count + neededCount); } if (hasAbstractMethods) { typeDeclaration.bits |= ASTNode.HasAbstractMethods; } return typeDeclaration; }
From source file:com.codenvy.ide.ext.java.server.internal.core.NamedMember.java
License:Open Source License
private void appendTypeParameters(StringBuffer buffer) throws JavaModelException { ITypeParameter[] typeParameters = getTypeParameters(); int length = typeParameters.length; if (length == 0) return;//from w w w . j a v a 2 s . c o m buffer.append('<'); for (int i = 0; i < length; i++) { ITypeParameter typeParameter = typeParameters[i]; buffer.append(typeParameter.getElementName()); String[] bounds = typeParameter.getBounds(); int boundsLength = bounds.length; if (boundsLength > 0) { buffer.append(" extends "); //$NON-NLS-1$ for (int j = 0; j < boundsLength; j++) { buffer.append(bounds[j]); if (j < boundsLength - 1) buffer.append(" & "); //$NON-NLS-1$ } } if (i < length - 1) buffer.append(", "); //$NON-NLS-1$ } buffer.append('>'); }
From source file:com.codenvy.ide.ext.java.server.internal.core.NamedMember.java
License:Open Source License
protected String getKey(IMethod method, boolean forceOpen) throws JavaModelException { StringBuffer key = new StringBuffer(); // declaring class String declaringKey = getKey((IType) method.getParent(), forceOpen); key.append(declaringKey);//from w w w. j a v a2 s.co m // selector key.append('.'); String selector = method.getElementName(); key.append(selector); // type parameters if (forceOpen) { ITypeParameter[] typeParameters = method.getTypeParameters(); int length = typeParameters.length; if (length > 0) { key.append('<'); for (int i = 0; i < length; i++) { ITypeParameter typeParameter = typeParameters[i]; String[] bounds = typeParameter.getBounds(); int boundsLength = bounds.length; char[][] boundSignatures = new char[boundsLength][]; for (int j = 0; j < boundsLength; j++) { boundSignatures[j] = Signature.createCharArrayTypeSignature(bounds[j].toCharArray(), method.isBinary()); CharOperation.replace(boundSignatures[j], '.', '/'); } char[] sig = Signature.createTypeParameterSignature( typeParameter.getElementName().toCharArray(), boundSignatures); key.append(sig); } key.append('>'); } } // parameters key.append('('); String[] parameters = method.getParameterTypes(); for (int i = 0, length = parameters.length; i < length; i++) key.append(parameters[i].replace('.', '/')); key.append(')'); // return type if (forceOpen) key.append(method.getReturnType().replace('.', '/')); else key.append('V'); return key.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeParameterPattern.java
License:Open Source License
/** * @param findDeclarations//from w w w . ja v a 2s . c o m * @param findReferences * @param typeParameter * @param matchRule */ public TypeParameterPattern(boolean findDeclarations, boolean findReferences, ITypeParameter typeParameter, int matchRule) { super(TYPE_PARAM_PATTERN, matchRule); this.findDeclarations = findDeclarations; // set to find declarations & all occurences this.findReferences = findReferences; // set to find references & all occurences this.typeParameter = typeParameter; this.name = typeParameter.getElementName().toCharArray(); // store type parameter name IMember member = typeParameter.getDeclaringMember(); this.declaringMemberName = member.getElementName().toCharArray(); // store type parameter declaring member name // For method type parameter, store also declaring class name and parameters type names if (member instanceof IMethod) { IMethod method = (IMethod) member; this.methodDeclaringClassName = method.getParent().getElementName().toCharArray(); String[] parameters = method.getParameterTypes(); int length = parameters.length; this.methodArgumentTypes = new char[length][]; for (int i = 0; i < length; i++) { this.methodArgumentTypes[i] = Signature.toCharArray(parameters[i].toCharArray()); } } }
From source file:com.github.ajaxsys.jdtx.utils.JDTUtils.java
License:Open Source License
public static Collection<String> getTypeParameterNames(IType type) throws IllegalArgumentException, JavaModelException { if (type == null) { throw new IllegalArgumentException("type == null"); }//from ww w .j a v a 2 s.c o m ITypeParameter[] tp = type.getTypeParameters(); Collection<String> typeParameterNames = new ArrayList<String>(); for (ITypeParameter p : tp) { typeParameterNames.add(p.getElementName()); } return typeParameterNames; }