use of org.eclipse.jdt.core.dom.SimpleType in project che by eclipse.
the class InferTypeArgumentsRefactoring method rewriteTypeVariable.
private static ParameterizedType rewriteTypeVariable(TypeVariable2 typeCv, CompilationUnitRewrite rewrite, InferTypeArgumentsTCModel tCModel, boolean leaveUnconstraindRaw, SimpleType[] types) {
ASTNode node = typeCv.getRange().getNode(rewrite.getRoot());
if (node instanceof Name && node.getParent() instanceof Type) {
Type originalType = (Type) node.getParent();
if (types != null && !has(types, originalType))
return null;
// Must rewrite all type arguments in one batch. Do the rewrite when the first one is encountered; skip the others.
Object rewritten = originalType.getProperty(REWRITTEN);
if (rewritten == REWRITTEN)
return null;
originalType.setProperty(REWRITTEN, REWRITTEN);
ArrayList<CollectionElementVariable2> typeArgumentCvs = getTypeArgumentCvs(typeCv, tCModel);
Type[] typeArguments = getTypeArguments(originalType, typeArgumentCvs, rewrite, tCModel, leaveUnconstraindRaw);
if (typeArguments == null)
return null;
Type movingType = (Type) rewrite.getASTRewrite().createMoveTarget(originalType);
ParameterizedType newType = rewrite.getAST().newParameterizedType(movingType);
for (int i = 0; i < typeArguments.length; i++) {
newType.typeArguments().add(typeArguments[i]);
}
rewrite.getASTRewrite().replace(originalType, newType, rewrite.createGroupDescription(RefactoringCoreMessages.InferTypeArgumentsRefactoring_addTypeArguments));
return newType;
} else {
//TODO: other node types?
return null;
}
}
use of org.eclipse.jdt.core.dom.SimpleType in project che by eclipse.
the class Java50Fix method getRawReference.
private static SimpleType getRawReference(MethodInvocation invocation, CompilationUnit compilationUnit) {
Name name1 = (Name) invocation.getStructuralProperty(MethodInvocation.NAME_PROPERTY);
if (name1 instanceof SimpleName) {
SimpleType rawReference = getRawReference((SimpleName) name1, compilationUnit);
if (rawReference != null) {
return rawReference;
}
}
Expression expr = (Expression) invocation.getStructuralProperty(MethodInvocation.EXPRESSION_PROPERTY);
if (expr instanceof SimpleName) {
SimpleType rawReference = getRawReference((SimpleName) expr, compilationUnit);
if (rawReference != null) {
return rawReference;
}
} else if (expr instanceof QualifiedName) {
Name name = (Name) expr;
while (name instanceof QualifiedName) {
SimpleName simpleName = (SimpleName) name.getStructuralProperty(QualifiedName.NAME_PROPERTY);
SimpleType rawReference = getRawReference(simpleName, compilationUnit);
if (rawReference != null) {
return rawReference;
}
name = (Name) name.getStructuralProperty(QualifiedName.QUALIFIER_PROPERTY);
}
if (name instanceof SimpleName) {
SimpleType rawReference = getRawReference((SimpleName) name, compilationUnit);
if (rawReference != null) {
return rawReference;
}
}
} else if (expr instanceof MethodInvocation) {
SimpleType rawReference = getRawReference((MethodInvocation) expr, compilationUnit);
if (rawReference != null) {
return rawReference;
}
}
return null;
}
use of org.eclipse.jdt.core.dom.SimpleType in project che by eclipse.
the class Java50Fix method isRawTypeReference.
private static boolean isRawTypeReference(ASTNode node) {
if (!(node instanceof SimpleType))
return false;
ITypeBinding typeBinding = ((SimpleType) node).resolveBinding();
if (typeBinding == null)
return false;
ITypeBinding binding = typeBinding.getTypeDeclaration();
if (binding == null)
return false;
ITypeBinding[] parameters = binding.getTypeParameters();
if (parameters.length == 0)
return false;
return true;
}
use of org.eclipse.jdt.core.dom.SimpleType in project che by eclipse.
the class Java50Fix method createRawTypeReferenceOperations.
private static SimpleType createRawTypeReferenceOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> operations) {
if (hasFatalError(compilationUnit))
return null;
List<SimpleType> result = new ArrayList<SimpleType>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation problem = locations[i];
if (isRawTypeReferenceProblem(problem.getProblemId())) {
ASTNode node = problem.getCoveredNode(compilationUnit);
if (node instanceof ClassInstanceCreation) {
Type rawReference = (Type) node.getStructuralProperty(ClassInstanceCreation.TYPE_PROPERTY);
if (isRawTypeReference(rawReference)) {
result.add((SimpleType) rawReference);
}
} else if (node instanceof SimpleName) {
ASTNode rawReference = node.getParent();
if (isRawTypeReference(rawReference)) {
ASTNode parent = rawReference.getParent();
if (!(parent instanceof ArrayType || parent instanceof ParameterizedType))
result.add((SimpleType) rawReference);
}
} else if (node instanceof MethodInvocation) {
MethodInvocation invocation = (MethodInvocation) node;
SimpleType rawReference = getRawReference(invocation, compilationUnit);
if (rawReference != null) {
result.add(rawReference);
}
}
}
}
if (result.size() == 0)
return null;
SimpleType[] types = result.toArray(new SimpleType[result.size()]);
operations.add(new AddTypeParametersOperation(types));
return types[0];
}
use of org.eclipse.jdt.core.dom.SimpleType in project che by eclipse.
the class PotentialProgrammingProblemsFix method getSelectedName.
private static SimpleName getSelectedName(CompilationUnit compilationUnit, IProblemLocation problem) {
final ASTNode selection = problem.getCoveredNode(compilationUnit);
if (selection == null)
return null;
Name name = null;
if (selection instanceof SimpleType) {
name = ((SimpleType) selection).getName();
} else if (selection instanceof NameQualifiedType) {
name = ((NameQualifiedType) selection).getName();
} else if (selection instanceof QualifiedType) {
name = ((QualifiedType) selection).getName();
} else if (selection instanceof ParameterizedType) {
final ParameterizedType type = (ParameterizedType) selection;
final Type raw = type.getType();
if (raw instanceof SimpleType)
name = ((SimpleType) raw).getName();
else if (raw instanceof NameQualifiedType)
name = ((NameQualifiedType) raw).getName();
else if (raw instanceof QualifiedType)
name = ((QualifiedType) raw).getName();
} else if (selection instanceof Name) {
name = (Name) selection;
}
if (name == null)
return null;
if (name.isSimpleName()) {
return (SimpleName) name;
} else {
return ((QualifiedName) name).getName();
}
}
Aggregations