use of org.eclipse.jdt.core.dom.TypeParameter in project che by eclipse.
the class JavadocTagsSubProcessor method getPreviousTypeParamNames.
public static Set<String> getPreviousTypeParamNames(List<TypeParameter> typeParams, ASTNode missingNode) {
Set<String> previousNames = new HashSet<String>();
for (int i = 0; i < typeParams.size(); i++) {
TypeParameter curr = typeParams.get(i);
if (curr == missingNode) {
return previousNames;
}
previousNames.add('<' + curr.getName().getIdentifier() + '>');
}
return previousNames;
}
use of org.eclipse.jdt.core.dom.TypeParameter in project che by eclipse.
the class TypeContextChecker method appendTypeParameters.
private static void appendTypeParameters(StringBuffer buf, List<TypeParameter> typeParameters) {
int typeParametersCount = typeParameters.size();
if (typeParametersCount > 0) {
buf.append('<');
for (int i = 0; i < typeParametersCount; i++) {
TypeParameter typeParameter = typeParameters.get(i);
buf.append(ASTNodes.asString(typeParameter));
if (i < typeParametersCount - 1)
buf.append(',');
}
buf.append('>');
}
}
use of org.eclipse.jdt.core.dom.TypeParameter in project che by eclipse.
the class ExtractMethodRefactoring method createNewMethodDeclaration.
private MethodDeclaration createNewMethodDeclaration() {
MethodDeclaration result = fAST.newMethodDeclaration();
int modifiers = fVisibility;
BodyDeclaration enclosingBodyDeclaration = fAnalyzer.getEnclosingBodyDeclaration();
boolean isDestinationInterface = isDestinationInterface();
if (isDestinationInterface && !(enclosingBodyDeclaration instanceof MethodDeclaration && enclosingBodyDeclaration.getParent() == fDestination && Modifier.isPublic(enclosingBodyDeclaration.getModifiers()))) {
modifiers = Modifier.NONE;
}
boolean shouldBeStatic = false;
ASTNode currentParent = enclosingBodyDeclaration;
do {
if (currentParent instanceof BodyDeclaration) {
shouldBeStatic = shouldBeStatic || JdtFlags.isStatic((BodyDeclaration) currentParent);
}
currentParent = currentParent.getParent();
} while (!shouldBeStatic && currentParent != null && currentParent != fDestination);
if (shouldBeStatic || fAnalyzer.getForceStatic() || forceStatic()) {
modifiers |= Modifier.STATIC;
} else if (isDestinationInterface) {
modifiers |= Modifier.DEFAULT;
}
ITypeBinding[] typeVariables = computeLocalTypeVariables(modifiers);
List<TypeParameter> typeParameters = result.typeParameters();
for (int i = 0; i < typeVariables.length; i++) {
TypeParameter parameter = fAST.newTypeParameter();
parameter.setName(fAST.newSimpleName(typeVariables[i].getName()));
ITypeBinding[] bounds = typeVariables[i].getTypeBounds();
for (int j = 0; j < bounds.length; j++) if (//$NON-NLS-1$
!"java.lang.Object".equals(bounds[j].getQualifiedName()))
parameter.typeBounds().add(fImportRewriter.addImport(bounds[j], fAST));
typeParameters.add(parameter);
}
result.modifiers().addAll(ASTNodeFactory.newModifiers(fAST, modifiers));
result.setReturnType2((Type) ASTNode.copySubtree(fAST, fAnalyzer.getReturnType()));
result.setName(fAST.newSimpleName(fMethodName));
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(enclosingBodyDeclaration, fImportRewriter);
List<SingleVariableDeclaration> parameters = result.parameters();
for (int i = 0; i < fParameterInfos.size(); i++) {
ParameterInfo info = fParameterInfos.get(i);
VariableDeclaration infoDecl = getVariableDeclaration(info);
SingleVariableDeclaration parameter = fAST.newSingleVariableDeclaration();
parameter.modifiers().addAll(ASTNodeFactory.newModifiers(fAST, ASTNodes.getModifiers(infoDecl)));
parameter.setType(ASTNodeFactory.newType(fAST, infoDecl, fImportRewriter, context));
parameter.setName(fAST.newSimpleName(info.getNewName()));
parameter.setVarargs(info.isNewVarargs());
parameters.add(parameter);
}
List<Type> exceptions = result.thrownExceptionTypes();
ITypeBinding[] exceptionTypes = fAnalyzer.getExceptions(fThrowRuntimeExceptions);
for (int i = 0; i < exceptionTypes.length; i++) {
ITypeBinding exceptionType = exceptionTypes[i];
exceptions.add(fImportRewriter.addImport(exceptionType, fAST, context));
}
return result;
}
use of org.eclipse.jdt.core.dom.TypeParameter in project che by eclipse.
the class IntroduceFactoryRefactoring method copyTypeParameters.
/**
* Copies the constructor's parent type's type parameters, if any, as
* method type parameters of the new static factory method. (Recall
* that static methods can't refer to type arguments of the enclosing
* class, since they have no instance to serve as a context.)<br>
* Makes sure to copy the bounds from the owning type, to ensure that the
* return type of the factory method satisfies the bounds of the type
* being instantiated.<br>
* E.g., for ctor Foo() in the type Foo<T extends Number>, be sure that
* the factory method is declared as<br>
* <code>static <T extends Number> Foo<T> createFoo()</code><br>
* and not simply<br>
* <code>static <T> Foo<T> createFoo()</code><br>
* or the compiler will bark.
* @param ast utility object needed to create ASTNode's for the new method
* @param newMethod the method onto which to copy the type parameters
*/
private void copyTypeParameters(AST ast, MethodDeclaration newMethod) {
ITypeBinding[] ctorOwnerTypeParms = fCtorBinding.getDeclaringClass().getTypeParameters();
List<TypeParameter> factoryMethodTypeParms = newMethod.typeParameters();
for (int i = 0; i < ctorOwnerTypeParms.length; i++) {
TypeParameter newParm = ast.newTypeParameter();
ITypeBinding[] parmTypeBounds = ctorOwnerTypeParms[i].getTypeBounds();
List<Type> newParmBounds = newParm.typeBounds();
newParm.setName(ast.newSimpleName(ctorOwnerTypeParms[i].getName()));
for (int b = 0; b < parmTypeBounds.length; b++) {
if (parmTypeBounds[b].isClass() && parmTypeBounds[b].getSuperclass() == null)
continue;
Type newBound = fImportRewriter.addImport(parmTypeBounds[b], ast);
newParmBounds.add(newBound);
}
factoryMethodTypeParms.add(newParm);
}
}
use of org.eclipse.jdt.core.dom.TypeParameter in project flux by eclipse.
the class ASTResolving method internalGetPossibleTypeKinds.
private static int internalGetPossibleTypeKinds(ASTNode node) {
int kind = SimilarElementsRequestor.ALL_TYPES;
int mask = SimilarElementsRequestor.ALL_TYPES | SimilarElementsRequestor.VOIDTYPE;
ASTNode parent = node.getParent();
while (parent instanceof QualifiedName) {
if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
return SimilarElementsRequestor.REF_TYPES;
}
node = parent;
parent = parent.getParent();
mask = SimilarElementsRequestor.REF_TYPES;
}
while (parent instanceof Type) {
if (parent instanceof QualifiedType) {
if (node.getLocationInParent() == QualifiedType.QUALIFIER_PROPERTY) {
return mask & (SimilarElementsRequestor.REF_TYPES);
}
mask &= SimilarElementsRequestor.REF_TYPES;
} else if (parent instanceof NameQualifiedType) {
if (node.getLocationInParent() == NameQualifiedType.QUALIFIER_PROPERTY) {
return mask & (SimilarElementsRequestor.REF_TYPES);
}
mask &= SimilarElementsRequestor.REF_TYPES;
} else if (parent instanceof ParameterizedType) {
if (node.getLocationInParent() == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) {
return mask & SimilarElementsRequestor.REF_TYPES_AND_VAR;
}
mask &= SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
} else if (parent instanceof WildcardType) {
if (node.getLocationInParent() == WildcardType.BOUND_PROPERTY) {
return mask & SimilarElementsRequestor.REF_TYPES_AND_VAR;
}
}
node = parent;
parent = parent.getParent();
}
switch(parent.getNodeType()) {
case ASTNode.TYPE_DECLARATION:
if (node.getLocationInParent() == TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY) {
kind = SimilarElementsRequestor.INTERFACES;
} else if (node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) {
kind = SimilarElementsRequestor.CLASSES;
}
break;
case ASTNode.ENUM_DECLARATION:
kind = SimilarElementsRequestor.INTERFACES;
break;
case ASTNode.METHOD_DECLARATION:
if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
kind = SimilarElementsRequestor.CLASSES;
} else if (node.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
kind = SimilarElementsRequestor.ALL_TYPES | SimilarElementsRequestor.VOIDTYPE;
}
break;
case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
kind = SimilarElementsRequestor.PRIMITIVETYPES | SimilarElementsRequestor.ANNOTATIONS | SimilarElementsRequestor.ENUMS;
break;
case ASTNode.INSTANCEOF_EXPRESSION:
kind = SimilarElementsRequestor.REF_TYPES;
break;
case ASTNode.THROW_STATEMENT:
kind = SimilarElementsRequestor.CLASSES;
break;
case ASTNode.CLASS_INSTANCE_CREATION:
if (((ClassInstanceCreation) parent).getAnonymousClassDeclaration() == null) {
kind = SimilarElementsRequestor.CLASSES;
} else {
kind = SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
}
break;
case ASTNode.SINGLE_VARIABLE_DECLARATION:
int superParent = parent.getParent().getNodeType();
if (superParent == ASTNode.CATCH_CLAUSE) {
kind = SimilarElementsRequestor.CLASSES;
} else if (superParent == ASTNode.ENHANCED_FOR_STATEMENT) {
kind = SimilarElementsRequestor.REF_TYPES;
}
break;
case ASTNode.TAG_ELEMENT:
kind = SimilarElementsRequestor.REF_TYPES;
break;
case ASTNode.MARKER_ANNOTATION:
case ASTNode.SINGLE_MEMBER_ANNOTATION:
case ASTNode.NORMAL_ANNOTATION:
kind = SimilarElementsRequestor.ANNOTATIONS;
break;
case ASTNode.TYPE_PARAMETER:
if (((TypeParameter) parent).typeBounds().indexOf(node) > 0) {
kind = SimilarElementsRequestor.INTERFACES;
} else {
kind = SimilarElementsRequestor.REF_TYPES_AND_VAR;
}
break;
case ASTNode.TYPE_LITERAL:
kind = SimilarElementsRequestor.REF_TYPES;
break;
default:
}
return kind & mask;
}
Aggregations