use of org.eclipse.jdt.core.dom.NameQualifiedType in project che by eclipse.
the class UnresolvedElementsSubProcessor method getTypeProposals.
public static void getTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return;
}
int kind = evauateTypeKind(selectedNode, cu.getJavaProject());
if (kind == SimilarElementsRequestor.REF_TYPES) {
addEnhancedForWithoutTypeProposals(cu, selectedNode, proposals);
}
while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
selectedNode = selectedNode.getParent();
}
Name node = null;
if (selectedNode instanceof SimpleType) {
node = ((SimpleType) selectedNode).getName();
} else if (selectedNode instanceof NameQualifiedType) {
node = ((NameQualifiedType) selectedNode).getName();
} else if (selectedNode instanceof ArrayType) {
Type elementType = ((ArrayType) selectedNode).getElementType();
if (elementType.isSimpleType()) {
node = ((SimpleType) elementType).getName();
} else if (elementType.isNameQualifiedType()) {
node = ((NameQualifiedType) elementType).getName();
} else {
return;
}
} else if (selectedNode instanceof Name) {
node = (Name) selectedNode;
} else {
return;
}
// change to similar type proposals
addSimilarTypeProposals(kind, cu, node, IProposalRelevance.SIMILAR_TYPE, proposals);
while (node.getParent() instanceof QualifiedName) {
node = (Name) node.getParent();
}
if (selectedNode != node) {
kind = evauateTypeKind(node, cu.getJavaProject());
}
if ((kind & (SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES)) != 0) {
// only propose annotations when there are no other suggestions
kind &= ~SimilarElementsRequestor.ANNOTATIONS;
}
addNewTypeProposals(cu, node, kind, IProposalRelevance.NEW_TYPE, proposals);
ReorgCorrectionsSubProcessor.addProjectSetupFixProposal(context, problem, node.getFullyQualifiedName(), proposals);
}
use of org.eclipse.jdt.core.dom.NameQualifiedType 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();
}
}
use of org.eclipse.jdt.core.dom.NameQualifiedType 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;
}
use of org.eclipse.jdt.core.dom.NameQualifiedType in project flux by eclipse.
the class ASTNodes method getQualifiedTypeName.
/**
* Returns the (potentially qualified) name of a type, followed by array dimensions.
* Skips type arguments and type annotations.
*
* @param type a type that has a name
* @return the name, followed by array dimensions
* @since 3.10
*/
public static String getQualifiedTypeName(Type type) {
final StringBuffer buffer = new StringBuffer();
ASTVisitor visitor = new ASTVisitor() {
@Override
public boolean visit(SimpleType node) {
buffer.append(node.getName().getFullyQualifiedName());
return false;
}
@Override
public boolean visit(QualifiedType node) {
node.getQualifier().accept(this);
buffer.append('.');
buffer.append(node.getName().getIdentifier());
return false;
}
@Override
public boolean visit(NameQualifiedType node) {
buffer.append(node.getQualifier().getFullyQualifiedName());
buffer.append('.');
buffer.append(node.getName().getIdentifier());
return false;
}
@Override
public boolean visit(ParameterizedType node) {
node.getType().accept(this);
return false;
}
@Override
public void endVisit(ArrayType node) {
for (int i = 0; i < node.dimensions().size(); i++) {
//$NON-NLS-1$
buffer.append("[]");
}
}
};
type.accept(visitor);
return buffer.toString();
}
Aggregations