List of usage examples for org.eclipse.jdt.core.dom SwitchCase EXPRESSION_PROPERTY
ChildPropertyDescriptor EXPRESSION_PROPERTY
To view the source code for org.eclipse.jdt.core.dom SwitchCase EXPRESSION_PROPERTY.
Click Source Link
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void getVariableProposals(IInvocationContext context, IProblemLocation problem, IVariableBinding resolvedField, Map<String, Map> proposals) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); CompilationUnit astRoot = context.getASTRoot(); ASTNode selectedNode = problem.getCoveredNode(astRoot); if (selectedNode == null) { return;/*from ww w . j a v a2 s . c o m*/ } // type that defines the variable ITypeBinding binding = null; ITypeBinding declaringTypeBinding = Bindings.getBindingOfParentTypeContext(selectedNode); if (declaringTypeBinding == null) { return; } // possible type kind of the node boolean suggestVariableProposals = true; while (selectedNode instanceof ParenthesizedExpression) { selectedNode = ((ParenthesizedExpression) selectedNode).getExpression(); } Name node = null; switch (selectedNode.getNodeType()) { case ASTNode.SIMPLE_NAME: node = (SimpleName) selectedNode; if (!isVariableProposalSafe(node)) return; ASTNode parent = node.getParent(); StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); if (locationInParent == MethodInvocation.EXPRESSION_PROPERTY) { } else if (locationInParent == FieldAccess.NAME_PROPERTY) { Expression expression = ((FieldAccess) parent).getExpression(); if (expression != null) { binding = expression.resolveTypeBinding(); if (binding == null) { node = null; } } } else if (parent instanceof SimpleType) { suggestVariableProposals = false; } else if (parent instanceof QualifiedName) { Name qualifier = ((QualifiedName) parent).getQualifier(); if (qualifier != node) { binding = qualifier.resolveTypeBinding(); } else { } ASTNode outerParent = parent.getParent(); while (outerParent instanceof QualifiedName) { outerParent = outerParent.getParent(); } if (outerParent instanceof SimpleType) { suggestVariableProposals = false; } } else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding switchExp = ((SwitchStatement) node.getParent().getParent()).getExpression() .resolveTypeBinding(); if (switchExp != null && switchExp.isEnum()) { binding = switchExp; } } else if (locationInParent == SuperFieldAccess.NAME_PROPERTY) { binding = declaringTypeBinding.getSuperclass(); } break; case ASTNode.QUALIFIED_NAME: QualifiedName qualifierName = (QualifiedName) selectedNode; ITypeBinding qualifierBinding = qualifierName.getQualifier().resolveTypeBinding(); if (qualifierBinding != null) { node = qualifierName.getName(); binding = qualifierBinding; } else { node = qualifierName.getQualifier(); suggestVariableProposals = node.isSimpleName(); } if (selectedNode.getParent() instanceof SimpleType) { suggestVariableProposals = false; } break; case ASTNode.FIELD_ACCESS: FieldAccess access = (FieldAccess) selectedNode; Expression expression = access.getExpression(); if (expression != null) { binding = expression.resolveTypeBinding(); if (binding != null) { node = access.getName(); } } break; case ASTNode.SUPER_FIELD_ACCESS: binding = declaringTypeBinding.getSuperclass(); node = ((SuperFieldAccess) selectedNode).getName(); break; default: } if (node == null) { return; } if (!suggestVariableProposals) { return; } SimpleName simpleName = node.isSimpleName() ? (SimpleName) node : ((QualifiedName) node).getName(); boolean isWriteAccess = ASTResolving.isWriteAccess(node); if (resolvedField == null || binding == null || resolvedField.getDeclaringClass() != binding.getTypeDeclaration() && Modifier.isPrivate(resolvedField.getModifiers())) { // new fields addNewFieldProposals(cu, astRoot, binding, declaringTypeBinding, simpleName, isWriteAccess, proposals); } }
From source file:edu.illinois.jflow.core.transformations.code.ExtractClosureAnalyzer.java
License:Open Source License
private void checkExpression(RefactoringStatus status) { ASTNode[] nodes = getSelectedNodes(); if (nodes != null && nodes.length == 1) { ASTNode node = nodes[0];/*from ww w . j a v a2 s. com*/ if (node instanceof Type) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_type_reference, JavaStatusContext.create(fCUnit, node)); } else if (node.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_switch_case, JavaStatusContext.create(fCUnit, node)); } else if (node instanceof Annotation || ASTNodes.getParent(node, Annotation.class) != null) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_from_annotation, JavaStatusContext.create(fCUnit, node)); } } }
From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void getVariableProposals(IInvocationContext context, IProblemLocation problem, IVariableBinding resolvedField, Collection proposals) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); CompilationUnit astRoot = context.getASTRoot(); ASTNode selectedNode = problem.getCoveredNode(astRoot); if (selectedNode == null) { return;/*from w w w . j a v a2s . c om*/ } // type that defines the variable ITypeBinding binding = null; ITypeBinding declaringTypeBinding = Bindings.getBindingOfParentTypeContext(selectedNode); if (declaringTypeBinding == null) { return; } // possible type kind of the node boolean suggestVariableProposals = true; int typeKind = 0; while (selectedNode instanceof ParenthesizedExpression) { selectedNode = ((ParenthesizedExpression) selectedNode).getExpression(); } Name node = null; switch (selectedNode.getNodeType()) { case ASTNode.SIMPLE_NAME: node = (SimpleName) selectedNode; ASTNode parent = node.getParent(); StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); if (locationInParent == MethodInvocation.EXPRESSION_PROPERTY) { typeKind = SimilarElementsRequestor.CLASSES; } else if (locationInParent == FieldAccess.NAME_PROPERTY) { Expression expression = ((FieldAccess) parent).getExpression(); if (expression != null) { binding = expression.resolveTypeBinding(); if (binding == null) { node = null; } } } else if (parent instanceof SimpleType) { suggestVariableProposals = false; typeKind = SimilarElementsRequestor.REF_TYPES; } else if (parent instanceof QualifiedName) { Name qualifier = ((QualifiedName) parent).getQualifier(); if (qualifier != node) { binding = qualifier.resolveTypeBinding(); } else { typeKind = SimilarElementsRequestor.REF_TYPES & ~SimilarElementsRequestor.VARIABLES; } ASTNode outerParent = parent.getParent(); while (outerParent instanceof QualifiedName) { outerParent = outerParent.getParent(); } if (outerParent instanceof SimpleType) { typeKind = SimilarElementsRequestor.REF_TYPES & ~SimilarElementsRequestor.VARIABLES; suggestVariableProposals = false; } } else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding switchExp = ((SwitchStatement) node.getParent().getParent()).getExpression() .resolveTypeBinding(); if (switchExp != null && switchExp.isEnum()) { binding = switchExp; } } else if (locationInParent == SuperFieldAccess.NAME_PROPERTY) { binding = declaringTypeBinding.getSuperclass(); } break; case ASTNode.QUALIFIED_NAME: QualifiedName qualifierName = (QualifiedName) selectedNode; ITypeBinding qualifierBinding = qualifierName.getQualifier().resolveTypeBinding(); if (qualifierBinding != null) { node = qualifierName.getName(); binding = qualifierBinding; } else { node = qualifierName.getQualifier(); typeKind = SimilarElementsRequestor.REF_TYPES & ~SimilarElementsRequestor.VARIABLES; suggestVariableProposals = node.isSimpleName(); } if (selectedNode.getParent() instanceof SimpleType) { typeKind = SimilarElementsRequestor.REF_TYPES & ~SimilarElementsRequestor.VARIABLES; suggestVariableProposals = false; } break; case ASTNode.FIELD_ACCESS: FieldAccess access = (FieldAccess) selectedNode; Expression expression = access.getExpression(); if (expression != null) { binding = expression.resolveTypeBinding(); if (binding != null) { node = access.getName(); } } break; case ASTNode.SUPER_FIELD_ACCESS: binding = declaringTypeBinding.getSuperclass(); node = ((SuperFieldAccess) selectedNode).getName(); break; default: } if (node == null) { return; } // add type proposals if (typeKind != 0) { if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) { typeKind = typeKind & ~(SimilarElementsRequestor.ANNOTATIONS | SimilarElementsRequestor.ENUMS | SimilarElementsRequestor.VARIABLES); } int relevance = Character.isUpperCase(ASTNodes.getSimpleNameIdentifier(node).charAt(0)) ? 5 : -2; addSimilarTypeProposals(typeKind, cu, node, relevance + 1, proposals); addNewTypeProposals(cu, node, typeKind, relevance, proposals); } if (!suggestVariableProposals) { return; } SimpleName simpleName = node.isSimpleName() ? (SimpleName) node : ((QualifiedName) node).getName(); boolean isWriteAccess = ASTResolving.isWriteAccess(node); // similar variables addSimilarVariableProposals(cu, astRoot, binding, simpleName, isWriteAccess, proposals); if (resolvedField == null || binding == null || resolvedField.getDeclaringClass() != binding.getTypeDeclaration() && Modifier.isPrivate(resolvedField.getModifiers())) { // new fields addNewFieldProposals(cu, astRoot, binding, declaringTypeBinding, simpleName, isWriteAccess, proposals); // new parameters and local variables if (binding == null) { addNewVariableProposals(cu, node, simpleName, proposals); } } }
From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.ScopeAnalyzer.java
License:Open Source License
public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) { try {/*from www . j a v a 2 s .c o m*/ // special case for switch on enum if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression() .resolveTypeBinding(); if (binding != null && binding.isEnum()) { return getEnumContants(binding); } } ITypeBinding parentTypeBinding = OrganizeImportsHelper.getBindingOfParentType(selector); if (parentTypeBinding != null) { ITypeBinding binding = getQualifier(selector); DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); addTypeDeclarations(parentTypeBinding, flags, requestor); } else { addInherited(binding, flags, requestor); } List<IBinding> result = requestor.getResult(); return result.toArray(new IBinding[result.size()]); } return NO_BINDING; } finally { clearLists(); } }
From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.ScopeAnalyzer.java
License:Open Source License
public boolean isDeclaredInScope(IBinding declaration, SimpleName selector, int flags) { try {/*from w w w . ja v a 2 s . c o m*/ // special case for switch on enum if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression() .resolveTypeBinding(); if (binding != null && binding.isEnum()) { return hasEnumContants(declaration, binding.getTypeDeclaration()); } } ITypeBinding parentTypeBinding = OrganizeImportsHelper.getBindingOfParentTypeContext(selector); if (parentTypeBinding != null) { ITypeBinding binding = getQualifier(selector); SearchRequestor requestor = new SearchRequestor(declaration, parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); if (requestor.found()) return requestor.isVisible(); addTypeDeclarations(parentTypeBinding, flags, requestor); if (requestor.found()) return requestor.isVisible(); } else { addInherited(binding, flags, requestor); if (requestor.found()) return requestor.isVisible(); } } return false; } finally { clearLists(); } }