use of org.eclipse.jdt.core.dom.QualifiedName 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.QualifiedName in project che by eclipse.
the class ReorgCorrectionsSubProcessor method importNotFoundProposals.
public static void importNotFoundProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return;
}
ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
if (importDeclaration == null) {
return;
}
if (!importDeclaration.isOnDemand()) {
Name name = importDeclaration.getName();
if (importDeclaration.isStatic() && name.isQualifiedName()) {
name = ((QualifiedName) name).getQualifier();
}
int kind = JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? SimilarElementsRequestor.REF_TYPES : SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
UnresolvedElementsSubProcessor.addNewTypeProposals(cu, name, kind, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
}
String name = ASTNodes.asString(importDeclaration.getName());
if (importDeclaration.isOnDemand()) {
//$NON-NLS-1$
name = JavaModelUtil.concatenateName(name, "*");
}
addProjectSetupFixProposal(context, problem, name, proposals);
}
use of org.eclipse.jdt.core.dom.QualifiedName in project che by eclipse.
the class NewVariableCorrectionProposal method evaluateFieldModifiers.
private int evaluateFieldModifiers(ASTNode newTypeDecl) {
if (fSenderBinding.isAnnotation()) {
return 0;
}
if (fSenderBinding.isInterface()) {
// for interface members copy the modifiers from an existing field
FieldDeclaration[] fieldDecls = ((TypeDeclaration) newTypeDecl).getFields();
if (fieldDecls.length > 0) {
return fieldDecls[0].getModifiers();
}
return 0;
}
int modifiers = 0;
if (fVariableKind == CONST_FIELD) {
modifiers |= Modifier.FINAL | Modifier.STATIC;
} else {
ASTNode parent = fOriginalNode.getParent();
if (parent instanceof QualifiedName) {
IBinding qualifierBinding = ((QualifiedName) parent).getQualifier().resolveBinding();
if (qualifierBinding instanceof ITypeBinding) {
modifiers |= Modifier.STATIC;
}
} else if (ASTResolving.isInStaticContext(fOriginalNode)) {
modifiers |= Modifier.STATIC;
}
}
ASTNode node = ASTResolving.findParentType(fOriginalNode, true);
if (newTypeDecl.equals(node)) {
modifiers |= Modifier.PRIVATE;
} else if (node instanceof AnonymousClassDeclaration) {
modifiers |= Modifier.PROTECTED;
} else {
modifiers |= Modifier.PUBLIC;
}
return modifiers;
}
use of org.eclipse.jdt.core.dom.QualifiedName 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.QualifiedName 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