Example usage for org.eclipse.jdt.core.dom QualifiedName QUALIFIER_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom QualifiedName QUALIFIER_PROPERTY

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom QualifiedName QUALIFIER_PROPERTY.

Prototype

ChildPropertyDescriptor QUALIFIER_PROPERTY

To view the source code for org.eclipse.jdt.core.dom QualifiedName QUALIFIER_PROPERTY.

Click Source Link

Document

The "qualifier" structural property of this node type (child type: Name ).

Usage

From source file:de.ovgu.cide.export.physical.ahead.MethodObjectHelper.java

License:Open Source License

/**
 * replaces all implicit access to "this" with explicit access (i.e. writes
 * a this. before every method invocation or field access where possible)
 * //www .j  a  v  a 2 s. c  om
 * 
 * @param targetMethod
 * @param colorManager
 */
public static void makeThisAccessExplicit(final MethodDeclaration targetMethod) {
    final AST ast = targetMethod.getAST();
    final TypeDeclaration thisClass = RefactoringUtils.getContainingType(targetMethod);
    targetMethod.accept(new ASTVisitor() {
        @Override
        public boolean visit(MethodInvocation node) {
            if (node.getExpression() == null)
                node.setExpression(ast.newThisExpression());
            return super.visit(node);
        }

        @Override
        public boolean visit(FieldAccess node) {
            if (node.getExpression() == null)
                node.setExpression(ast.newThisExpression());
            return super.visit(node);
        }

        @Override
        public void endVisit(SimpleName node) {
            if (node.getLocationInParent() == FieldAccess.NAME_PROPERTY)
                return;
            if (node.getLocationInParent() == QualifiedName.NAME_PROPERTY)
                return;

            IBinding binding = ((Name) node).resolveBinding();
            if (binding instanceof IVariableBinding) {
                IVariableBinding vBinding = (IVariableBinding) binding;
                if (vBinding.isField()) {
                    ITypeBinding bc = vBinding.getDeclaringClass();
                    if (thisClass.resolveBinding() == bc) {
                        /*
                         * workaround if a field access is represented by a
                         * qualified name (this qualified name must be first
                         * replaced by a field access
                         */
                        if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
                            QualifiedName parent = (QualifiedName) node.getParent();
                            parent.setQualifier(ast.newSimpleName("notUsed"));
                            FieldAccess fieldAccess = ast.newFieldAccess();
                            RefactoringUtils.replaceASTNode(parent, fieldAccess);
                            fieldAccess.setExpression(node);
                            fieldAccess.setName(ast.newSimpleName(parent.getName().getIdentifier()));
                        }

                        FieldAccess fieldAccess = ast.newFieldAccess();
                        RefactoringUtils.replaceASTNode(node, fieldAccess);
                        fieldAccess.setExpression(ast.newThisExpression());
                        fieldAccess.setName(node);
                    }

                }
            }

        }
    });
}

From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.OrganizeImportsHelper.java

License:Open Source License

private static int internalGetPossibleTypeKinds(ASTNode node) {
    int kind = ALL_TYPES;

    int mask = ALL_TYPES | VOIDTYPE;

    ASTNode parent = node.getParent();//from   w w w  .j av  a  2 s.c  o  m
    while (parent instanceof QualifiedName) {
        if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
            return REF_TYPES;
        }
        node = parent;
        parent = parent.getParent();
        mask = REF_TYPES;
    }
    while (parent instanceof Type) {
        if (parent instanceof QualifiedType) {
            if (node.getLocationInParent() == QualifiedType.QUALIFIER_PROPERTY) {
                return mask & (REF_TYPES);
            }
            mask &= REF_TYPES;
        } else if (parent instanceof ParameterizedType) {
            if (node.getLocationInParent() == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) {
                return mask & REF_TYPES_AND_VAR;
            }
            mask &= CLASSES | INTERFACES;
        } else if (parent instanceof WildcardType) {
            if (node.getLocationInParent() == WildcardType.BOUND_PROPERTY) {
                return mask & 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 = INTERFACES;
        } else if (node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) {
            kind = CLASSES;
        }
        break;
    case ASTNode.ENUM_DECLARATION:
        kind = INTERFACES;
        break;
    case ASTNode.METHOD_DECLARATION:
        if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY) {
            kind = CLASSES;
        } else if (node.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
            kind = ALL_TYPES | VOIDTYPE;
        }
        break;
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
        kind = PRIMITIVETYPES | ANNOTATIONS | ENUMS;
        break;
    case ASTNode.INSTANCEOF_EXPRESSION:
        kind = REF_TYPES;
        break;
    case ASTNode.THROW_STATEMENT:
        kind = CLASSES;
        break;
    case ASTNode.CLASS_INSTANCE_CREATION:
        if (((ClassInstanceCreation) parent).getAnonymousClassDeclaration() == null) {
            kind = CLASSES;
        } else {
            kind = CLASSES | INTERFACES;
        }
        break;
    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        int superParent = parent.getParent().getNodeType();
        if (superParent == ASTNode.CATCH_CLAUSE) {
            kind = CLASSES;
        }
        break;
    case ASTNode.TAG_ELEMENT:
        kind = REF_TYPES;
        break;
    case ASTNode.MARKER_ANNOTATION:
    case ASTNode.SINGLE_MEMBER_ANNOTATION:
    case ASTNode.NORMAL_ANNOTATION:
        kind = ANNOTATIONS;
        break;
    case ASTNode.TYPE_PARAMETER:
        if (((TypeParameter) parent).typeBounds().indexOf(node) > 0) {
            kind = INTERFACES;
        } else {
            kind = REF_TYPES_AND_VAR;
        }
        break;
    case ASTNode.TYPE_LITERAL:
        kind = REF_TYPES;
        break;
    default:
    }
    return kind & mask;
}

From source file:org.eclipse.wb.core.model.JavaInfo.java

License:Open Source License

/**
 * @return the {@link ASTNode} that should be used to display given related {@link ASTNode}.
 *///from  www  . ja v a2s .  co  m
public static ASTNode getRelatedNodeForSource(ASTNode node) {
    ASTNode sourceNode = node;
    // part of invocation
    if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) {
        sourceNode = node.getParent();
    }
    if (node.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) {
        sourceNode = node.getParent();
    }
    if (node.getLocationInParent() == SuperConstructorInvocation.ARGUMENTS_PROPERTY) {
        sourceNode = node.getParent();
    }
    if (node.getLocationInParent() == SuperMethodInvocation.ARGUMENTS_PROPERTY) {
        sourceNode = node.getParent();
    }
    if (node.getLocationInParent() == ClassInstanceCreation.ARGUMENTS_PROPERTY) {
        sourceNode = node.getParent();
    }
    // javaInfo.foo = something
    if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
        QualifiedName qualifiedName = (QualifiedName) node.getParent();
        sourceNode = qualifiedName;
        if (qualifiedName.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) {
            sourceNode = qualifiedName.getParent();
        }
    }
    // done
    return sourceNode;
}

From source file:org.eclipse.wb.internal.core.model.util.MorphingSupport.java

License:Open Source License

@Override
protected void morph_properties(T newComponent) throws Exception {
    ComponentDescription newComponentDescription = newComponent.getDescription();
    // move related nodes
    for (ASTNode node : m_component.getRelatedNodes()) {
        // check if method invocation can exist in new component
        if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) {
            MethodInvocation invocation = (MethodInvocation) node.getParent();
            String signature = AstNodeUtils.getMethodSignature(invocation);
            if (newComponentDescription.getMethod(signature) == null) {
                m_editor.removeEnclosingStatement(invocation);
                continue;
            }//from ww w  .j  a  v  a  2s . c  o m
        }
        // check if assignment can exist in new component
        if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
            QualifiedName fieldAccess = (QualifiedName) node.getParent();
            if (fieldAccess.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) {
                String fieldName = fieldAccess.getName().getIdentifier();
                if (ReflectionUtils.getFieldByName(newComponentDescription.getComponentClass(),
                        fieldName) == null) {
                    m_editor.removeEnclosingStatement(node);
                    continue;
                }
            }
        }
        // OK, we can add this related node
        newComponent.addRelatedNode(node);
    }
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java

License:Open Source License

/**
 * Examples://w  w  w. j  a  v  a 2 s  . c o  m
 * 
 * <pre>
  * SWT.NONE = org.eclipse.swt.SWT.NONE
  * new JButton() = new javax.swing.JButton()
  * </pre>
 * 
 * @param theNode
 *          the {@link ASTNode} to get the source.
 * @param transformer
 *          the {@link Function} that can participate in node to source transformation by
 *          providing alternative source for some nodes. Can be <code>null</code>, in not
 *          additional transformation required. If transformer returns not <code>null</code>, we
 *          use it instead of its original source; if <code>null</code> - we continue with
 *          original source.
 * 
 * @return the source of {@link ASTNode} in "external form", i.e. with fully qualified types.
 */
@SuppressWarnings("restriction")
public String getExternalSource(final ASTNode theNode, final Function<ASTNode, String> transformer) {
    final StringBuffer buffer = new StringBuffer(getSource(theNode));
    // remember positions for all nodes
    final Map<ASTNode, Integer> nodePositions = Maps.newHashMap();
    theNode.accept(new ASTVisitor() {
        @Override
        public void postVisit(ASTNode _node) {
            nodePositions.put(_node, _node.getStartPosition());
        }
    });
    // replace "name" with "qualified name"
    theNode.accept(new org.eclipse.jdt.internal.corext.dom.GenericVisitor() {
        @Override
        protected boolean visitNode(ASTNode node) {
            if (transformer != null) {
                String source = transformer.apply(node);
                if (source != null) {
                    replace(node, source);
                    return false;
                }
            }
            return true;
        }

        @Override
        public void endVisit(SimpleName name) {
            if (!AstNodeUtils.isVariable(name)) {
                StructuralPropertyDescriptor location = name.getLocationInParent();
                if (location == SimpleType.NAME_PROPERTY || location == QualifiedName.QUALIFIER_PROPERTY
                        || location == ClassInstanceCreation.NAME_PROPERTY
                        || location == MethodInvocation.EXPRESSION_PROPERTY) {
                    String fullyQualifiedName = AstNodeUtils.getFullyQualifiedName(name, false);
                    replace(name, fullyQualifiedName);
                }
            }
        }

        /**
         * Replace given ASTNode with different source, with updating positions for other nodes.
         */
        private void replace(ASTNode node, String newSource) {
            int nodePosition = nodePositions.get(node);
            // update source
            {
                int sourceStart = nodePosition - theNode.getStartPosition();
                int sourceEnd = sourceStart + node.getLength();
                buffer.replace(sourceStart, sourceEnd, newSource);
            }
            // update positions for nodes
            int lengthDelta = newSource.length() - node.getLength();
            for (Map.Entry<ASTNode, Integer> entry : nodePositions.entrySet()) {
                Integer position = entry.getValue();
                if (position > nodePosition) {
                    entry.setValue(position + lengthDelta);
                }
            }
        }
    });
    // OK, we have updated source
    return buffer.toString();
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java

License:Open Source License

/**
 * @param node/*  ww  w . j ava 2  s.  co  m*/
 *          the {@link ASTNode} that represents should be qualifier of field.
 * 
 * @return the {@link Expression} ({@link QualifiedName} or {@link FieldAccess}) used as left side
 *         of {@link Assignment} to some field. May return <code>null</code>, if given node is not
 *         left part of {@link Assignment}.
 */
public static Expression getFieldAssignment(ASTNode node) {
    // FieldAccess = value
    if (node.getLocationInParent() == FieldAccess.EXPRESSION_PROPERTY) {
        FieldAccess fieldAccess = (FieldAccess) node.getParent();
        if (fieldAccess.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) {
            return fieldAccess;
        }
    }
    // QualifiedName = value
    if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
        QualifiedName qualifiedName = (QualifiedName) node.getParent();
        if (qualifiedName.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) {
            return qualifiedName;
        }
    }
    // not an Assignment part
    return null;
}

From source file:org.jboss.tools.arquillian.ui.internal.detectors.ArquillianResourceHyperlinkDetector.java

License:Open Source License

@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
        boolean canShowMultipleHyperlinks) {
    ITextEditor textEditor = (ITextEditor) getAdapter(ITextEditor.class);
    if (region == null || textEditor == null)
        return null;

    IEditorSite site = textEditor.getEditorSite();
    if (site == null)
        return null;

    ITypeRoot javaElement = JavaUI.getEditorInputTypeRoot(textEditor.getEditorInput());
    if (javaElement == null)
        return null;

    if (!ArquillianSearchEngine.isArquillianJUnitTest(javaElement.findPrimaryType(), false, false, false)) {
        return null;
    }//from  ww  w . jav a  2s.  co  m
    CompilationUnit ast = SharedASTProvider.getAST(javaElement, SharedASTProvider.WAIT_NO, null);
    if (ast == null)
        return null;

    ASTNode node = NodeFinder.perform(ast, region.getOffset(), 1);
    if (!(node instanceof StringLiteral))
        return null;

    if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY)
        return null;

    ASTNode parent = node.getParent();
    if (!(parent instanceof MethodInvocation)) {
        return null;
    }
    MethodInvocation methodInvocation = (MethodInvocation) parent;
    SimpleName name = methodInvocation.getName();
    String methodName = name.getFullyQualifiedName();
    if (!ArquillianUIUtil.ADD_AS_RESOURCE_METHOD.equals(methodName)
            && !ArquillianUIUtil.ADD_AS_MANIFEST_RESOURCE_METHOD.equals(methodName)
            && !ArquillianUIUtil.ADD_AS_WEB_INF_RESOURCE_METHOD.equals(methodName)) {
        return null;
    }
    while (parent != null) {
        parent = parent.getParent();
        if (parent instanceof MethodDeclaration) {
            MethodDeclaration methodDeclaration = (MethodDeclaration) parent;

            int modifiers = methodDeclaration.getModifiers();
            if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)) {
                IMethodBinding binding = methodDeclaration.resolveBinding();
                IMethod method = (IMethod) binding.getJavaElement();
                try {
                    String signature = method.getSignature();
                    if (!"()QArchive<*>;".equals(signature)) { //$NON-NLS-1$
                        break;
                    }
                } catch (JavaModelException e) {
                    ArquillianUIActivator.log(e);
                }
                IAnnotationBinding[] annotations = binding.getAnnotations();
                for (IAnnotationBinding annotationBinding : annotations) {
                    ITypeBinding typeBinding = annotationBinding.getAnnotationType();
                    if (ArquillianUtility.ORG_JBOSS_ARQUILLIAN_CONTAINER_TEST_API_DEPLOYMENT
                            .equals(typeBinding.getQualifiedName())) {
                        StringLiteral stringLiteral = (StringLiteral) node;
                        String resource = stringLiteral.getLiteralValue();
                        IFile file = getFile(resource, javaElement);
                        if (file != null) {
                            int start = node.getStartPosition();
                            int length = node.getLength();
                            if (length > 2) {
                                start++;
                                length -= 2;
                            }
                            IRegion stringLiteralRegion = new Region(start, length);
                            return new IHyperlink[] {
                                    new ArquillianResourceHyperlink(resource, stringLiteralRegion, file) };
                        }
                        break;
                    }

                }
            }
        }
    }

    return null;
}