Java 类org.eclipse.jdt.core.dom.StructuralPropertyDescriptor 实例源码

项目:eclipse.jdt.ls    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:che    文件:CodeStyleFix.java   
private void handleSimpleName(SimpleName node) {
  ASTNode firstExpression = node.getParent();
  if (firstExpression instanceof FieldAccess) {
    while (firstExpression instanceof FieldAccess) {
      firstExpression = ((FieldAccess) firstExpression).getExpression();
    }
    if (!(firstExpression instanceof SimpleName)) return;

    node = (SimpleName) firstExpression;
  } else if (firstExpression instanceof SuperFieldAccess) return;

  StructuralPropertyDescriptor parentDescription = node.getLocationInParent();
  if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY
      || parentDescription == SwitchCase.EXPRESSION_PROPERTY) return;

  IBinding binding = node.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return;

  handleVariable(node, (IVariableBinding) binding);
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
private void handleTypeBinding(ASTNode node, ITypeBinding typeBinding, boolean includeTypeParameters) {
    if (typeBinding == null) {
        StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
        //System.out.println(locationInParent.getId() + " has no type binding");
    } else {
        List<ITypeBinding> rawTypes = new ArrayList<ITypeBinding>();
        Set<String> dejavu = new HashSet<String>();
        this.appendRawTypes(rawTypes, dejavu, typeBinding, includeTypeParameters);
        for (ITypeBinding rawType : rawTypes) {
            if (!this.ignoreType(rawType)) {
                this.onTypeAccess(node, rawType);
            }
        }

    }
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
private void handleTypeBinding(ASTNode node, ITypeBinding typeBinding, boolean includeTypeParameters) {
    if (typeBinding == null) {
        StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
        //System.out.println(locationInParent.getId() + " has no type binding");
    } else {
        List<ITypeBinding> rawTypes = new ArrayList<ITypeBinding>();
        Set<String> dejavu = new HashSet<String>();
        this.appendRawTypes(rawTypes, dejavu, typeBinding, includeTypeParameters);
        for (ITypeBinding rawType : rawTypes) {
            if (!this.ignoreType(rawType)) {
                this.onTypeAccess(node, rawType);
            }
        }

    }
}
项目:java-driver    文件:GoGen.java   
private static List<String> structuralPropertyNamesOf(final List<Class<? extends ASTNode>> nodes) {
    final List<String> names = new ArrayList<>();
    for (final Class<? extends ASTNode> node : nodes) {
        try {
            final Method m = node.getDeclaredMethod("propertyDescriptors", int.class);
            final List l = (List) m.invoke(null, AST.JLS8);
            for (final Object o : l) {
                final StructuralPropertyDescriptor d = (StructuralPropertyDescriptor) o;
                names.add(d.getId());
            }
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
            throw new RuntimeException("unexpected exception", ex);
        }
    }
    return names;
}
项目:java-driver    文件:eclipseParser.java   
@Override
public void serialize(ASTNode node, JsonGenerator jG, SerializerProvider provider) throws IOException {
    List<StructuralPropertyDescriptor> descriptorList = node.structuralPropertiesForType();
    nCount++;
    jG.writeStartObject();

    for (StructuralPropertyDescriptor descriptor : descriptorList) {
        Object child = node.getStructuralProperty(descriptor);
        if (child instanceof List) {
            serializeChildList((List<ASTNode>) child, descriptor, provider);
        } else if (child instanceof ASTNode) {
            serializeChild((ASTNode) child, descriptor, provider);
        } else if (child != null) {
            jG.writeFieldName(descriptor.getId());
            jG.writeString(child.toString());
        }
    }
    jG.writeEndObject();
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Returns the type binding of the node's type context or null if the node is inside
 * an annotation, type parameter, super type declaration, or Javadoc of a top level type.
 * The result of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in the type's body.
 *
 * @param node an AST node
 * @return the type binding of the node's parent type context, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
    StructuralPropertyDescriptor lastLocation= null;

    while (node != null) {
        if (node instanceof AbstractTypeDeclaration) {
            AbstractTypeDeclaration decl= (AbstractTypeDeclaration) node;
            if (lastLocation == decl.getBodyDeclarationsProperty()
                    || lastLocation == decl.getJavadocProperty()) {
                return decl.resolveBinding();
            } else if (decl instanceof EnumDeclaration && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
                return decl.resolveBinding();
            }
        } else if (node instanceof AnonymousClassDeclaration) {
            return ((AnonymousClassDeclaration) node).resolveBinding();
        }
        lastLocation= node.getLocationInParent();
        node= node.getParent();
    }
    return null;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
/**
 * Returns whether an expression at the given location needs explicit boxing.
 *
 * @param expression the expression
 * @return <code>true</code> iff an expression at the given location needs explicit boxing
 * @since 3.6
 */
private static boolean needsExplicitBoxing(Expression expression) {
    StructuralPropertyDescriptor locationInParent= expression.getLocationInParent();
    if (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return needsExplicitBoxing((ParenthesizedExpression) expression.getParent());
    }

    if (locationInParent == ClassInstanceCreation.EXPRESSION_PROPERTY
            || locationInParent == FieldAccess.EXPRESSION_PROPERTY
            || locationInParent == MethodInvocation.EXPRESSION_PROPERTY) {
        return true;
    }

    return false;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static ASTNode findParent(ASTNode node, StructuralPropertyDescriptor[][] pathes) {
    for (int p= 0; p < pathes.length; p++) {
        StructuralPropertyDescriptor[] path= pathes[p];
        ASTNode current= node;
        int d= path.length - 1;
        for (; d >= 0 && current != null; d--) {
            StructuralPropertyDescriptor descriptor= path[d];
            if (!descriptor.equals(current.getLocationInParent())) {
                break;
            }
            current= current.getParent();
        }
        if (d < 0) {
            return current;
        }
    }
    return null;
}
项目:che    文件:Bindings.java   
/**
 * Returns the type binding of the node's type context or null if the node is inside an
 * annotation, type parameter, super type declaration, or Javadoc of a top level type. The result
 * of this method is equal to the result of {@link #getBindingOfParentType(ASTNode)} for nodes in
 * the type's body.
 *
 * @param node an AST node
 * @return the type binding of the node's parent type context, or <code>null</code>
 */
public static ITypeBinding getBindingOfParentTypeContext(ASTNode node) {
  StructuralPropertyDescriptor lastLocation = null;

  while (node != null) {
    if (node instanceof AbstractTypeDeclaration) {
      AbstractTypeDeclaration decl = (AbstractTypeDeclaration) node;
      if (lastLocation == decl.getBodyDeclarationsProperty()
          || lastLocation == decl.getJavadocProperty()) {
        return decl.resolveBinding();
      } else if (decl instanceof EnumDeclaration
          && lastLocation == EnumDeclaration.ENUM_CONSTANTS_PROPERTY) {
        return decl.resolveBinding();
      }
    } else if (node instanceof AnonymousClassDeclaration) {
      return ((AnonymousClassDeclaration) node).resolveBinding();
    }
    lastLocation = node.getLocationInParent();
    node = node.getParent();
  }
  return null;
}
项目:che    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
  if (locationInParent instanceof ChildListPropertyDescriptor
      && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
    // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation
    // ...
    return false;
  }
  if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
      || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
      || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
      || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
      || locationInParent == ForStatement.EXPRESSION_PROPERTY
      || locationInParent == WhileStatement.EXPRESSION_PROPERTY
      || locationInParent == DoStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.MESSAGE_PROPERTY
      || locationInParent == IfStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchCase.EXPRESSION_PROPERTY
      || locationInParent == ArrayAccess.INDEX_PROPERTY
      || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
      || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
      || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
    return false;
  }
  return true;
}
项目:che    文件:Java50Fix.java   
private static ASTNode getDeclaringNode(ASTNode selectedNode) {
  ASTNode declaringNode = null;
  if (selectedNode instanceof MethodDeclaration) {
    declaringNode = selectedNode;
  } else if (selectedNode instanceof SimpleName) {
    StructuralPropertyDescriptor locationInParent = selectedNode.getLocationInParent();
    if (locationInParent == MethodDeclaration.NAME_PROPERTY
        || locationInParent == TypeDeclaration.NAME_PROPERTY) {
      declaringNode = selectedNode.getParent();
    } else if (locationInParent == VariableDeclarationFragment.NAME_PROPERTY) {
      declaringNode = selectedNode.getParent().getParent();
    }
  }
  return declaringNode;
}
项目:che    文件:RefactoringAvailabilityTester.java   
private static ASTNode getInlineableMethodNode(ASTNode node, IJavaElement unit) {
  if (node == null) return null;
  switch (node.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
      StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
      if (locationInParent == MethodDeclaration.NAME_PROPERTY) {
        return node.getParent();
      } else if (locationInParent == MethodInvocation.NAME_PROPERTY
          || locationInParent == SuperMethodInvocation.NAME_PROPERTY) {
        return unit instanceof ICompilationUnit
            ? node.getParent()
            : null; // don't start on invocations in binary
      }
      return null;
    case ASTNode.EXPRESSION_STATEMENT:
      node = ((ExpressionStatement) node).getExpression();
  }
  switch (node.getNodeType()) {
    case ASTNode.METHOD_DECLARATION:
      return node;
    case ASTNode.METHOD_INVOCATION:
    case ASTNode.SUPER_METHOD_INVOCATION:
    case ASTNode.CONSTRUCTOR_INVOCATION:
      return unit instanceof ICompilationUnit
          ? node
          : null; // don't start on invocations in binary
  }
  return null;
}
项目:che    文件:SourceAnalyzer.java   
@Override
public boolean visit(SimpleName node) {
  addReferencesToName(node);
  IBinding binding = node.resolveBinding();
  if (binding instanceof ITypeBinding) {
    ITypeBinding type = (ITypeBinding) binding;
    if (type.isTypeVariable()) {
      addTypeVariableReference(type, node);
    }
  } else if (binding instanceof IVariableBinding) {
    IVariableBinding vb = (IVariableBinding) binding;
    if (vb.isField() && !isStaticallyImported(node)) {
      Name topName = ASTNodes.getTopMostName(node);
      if (node == topName || node == ASTNodes.getLeftMostSimpleName(topName)) {
        StructuralPropertyDescriptor location = node.getLocationInParent();
        if (location != SingleVariableDeclaration.NAME_PROPERTY
            && location != VariableDeclarationFragment.NAME_PROPERTY) {
          fImplicitReceivers.add(node);
        }
      }
    } else if (!vb.isField()) {
      // we have a local. Check if it is a parameter.
      ParameterData data = fParameters.get(binding);
      if (data != null) {
        ASTNode parent = node.getParent();
        if (parent instanceof Expression) {
          int precedence = OperatorPrecedence.getExpressionPrecedence((Expression) parent);
          if (precedence != Integer.MAX_VALUE) {
            data.setOperatorPrecedence(precedence);
          }
        }
      }
    }
  }
  return true;
}
项目:che    文件:IntroduceFactoryRefactoring.java   
/**
 * Finds and returns the <code>ASTNode</code> for the given source text selection, if it is an
 * entire constructor call or the class name portion of a constructor call or constructor
 * declaration, or null otherwise.
 *
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 */
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
  ASTNode node = ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
  if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return node;
  if (node.getNodeType() == ASTNode.METHOD_DECLARATION
      && ((MethodDeclaration) node).isConstructor()) return node;
  // we have some sub node. Make sure its the right child of the parent
  StructuralPropertyDescriptor location = node.getLocationInParent();
  ASTNode parent = node.getParent();
  if (location == ClassInstanceCreation.TYPE_PROPERTY) {
    return parent;
  } else if (location == MethodDeclaration.NAME_PROPERTY
      && ((MethodDeclaration) parent).isConstructor()) {
    return parent;
  }
  return null;
}
项目:che    文件:SemanticHighlightings.java   
@Override
public boolean consumes(SemanticToken token) {
  SimpleName node = token.getNode();
  StructuralPropertyDescriptor location = node.getLocationInParent();
  if (location == VariableDeclarationFragment.NAME_PROPERTY
      || location == SingleVariableDeclaration.NAME_PROPERTY) {
    ASTNode parent = node.getParent();
    if (parent instanceof VariableDeclaration) {
      parent = parent.getParent();
      return parent == null || !(parent instanceof FieldDeclaration);
    }
  }
  return false;
}
项目:eclipse-filecompletion    文件:FileClassFinder.java   
public static boolean isStringNodeInPatternElement(StringLiteral node) {
    ASTNode parent = node.getParent();
    StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
    if (locationInParent.isChildProperty() && !locationInParent.isChildListProperty()) {
        return false;
    }
    if (parent instanceof MethodInvocation) {
        MethodInvocation parentMethodInvocation = (MethodInvocation) parent;
        if (isPatternPart(parentMethodInvocation)) {
            return true;
        } else if (isStringPattern(parentMethodInvocation)) {
            return true;
        } else {

        }
    } else {
        LOG.fine("not ClassInstanceCreation " + parent.getClass().getName() + " " + parent);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:IntroduceParameterObjectProcessor.java   
@Override
protected boolean shouldReport(IProblem problem, CompilationUnit cu) {
    if (!super.shouldReport(problem, cu))
        return false;
    ASTNode node= ASTNodeSearchUtil.getAstNode(cu, problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1);
    if (node instanceof Type) {
        Type type= (Type) node;
        if (problem.getID() == IProblem.UndefinedType && getClassName().equals(ASTNodes.getTypeName(type))) {
            return false;
        }
    }
    if (node instanceof Name) {
        Name name= (Name) node;
        if (problem.getID() == IProblem.ImportNotFound && getPackage().indexOf(name.getFullyQualifiedName()) != -1)
            return false;
        if (problem.getID() == IProblem.MissingTypeInMethod) {
            StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
            String[] arguments= problem.getArguments();
            if ((locationInParent == MethodInvocation.NAME_PROPERTY || locationInParent == SuperMethodInvocation.NAME_PROPERTY)
                    && arguments.length > 3
                    && arguments[3].endsWith(getClassName()))
                return false;
        }
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:InlineConstantRefactoring.java   
@Override
public boolean visit(Name name) {
    StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
    if (locationInParent == ExpressionMethodReference.NAME_PROPERTY
            || locationInParent == TypeMethodReference.NAME_PROPERTY
            || locationInParent == SuperMethodReference.NAME_PROPERTY) {
        return false;
    }

    SimpleName leftmost= getLeftmost(name);

    IBinding leftmostBinding= leftmost.resolveBinding();
    if (leftmostBinding instanceof IVariableBinding || leftmostBinding instanceof IMethodBinding || leftmostBinding instanceof ITypeBinding) {
        if (shouldUnqualify(leftmost))
            unqualifyMemberName(leftmost);
        else
            qualifyUnqualifiedMemberNameIfNecessary(leftmost);
    }

    if (leftmostBinding instanceof ITypeBinding) {
        String addedImport= fNewLocationCuRewrite.getImportRewrite().addImport((ITypeBinding)leftmostBinding, fNewLocationContext);
        fNewLocationCuRewrite.getImportRemover().registerAddedImport(addedImport);
    }

    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodes.java   
public static ASTNode findParent(ASTNode node, StructuralPropertyDescriptor[][] pathes) {
    for (int p= 0; p < pathes.length; p++) {
        StructuralPropertyDescriptor[] path= pathes[p];
        ASTNode current= node;
        int d= path.length - 1;
        for (; d >= 0 && current != null; d--) {
            StructuralPropertyDescriptor descriptor= path[d];
            if (!descriptor.equals(current.getLocationInParent()))
                break;
            current= current.getParent();
        }
        if (d < 0)
            return current;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InternalASTRewrite.java   
void postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) {
    if(property.isChildListProperty()) {

        ListRewriteEvent event = getListEvent(node, property);
        List list = (List)node.getStructuralProperty(property);
        int i = list.indexOf(child);
        int s = list.size();
        int index;
        if(i + 1 < s) {
            ASTNode nextNode = (ASTNode)list.get(i + 1);
            index = event.getIndex(nextNode, ListRewriteEvent.NEW);
        } else {
            index = -1;
        }
        event.insert(child, index);
        if(child != null) {
            markAsMoveOrCopyTarget(node, child);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeStyleFix.java   
private void handleSimpleName(SimpleName node) {
    ASTNode firstExpression= node.getParent();
    if (firstExpression instanceof FieldAccess) {
        while (firstExpression instanceof FieldAccess) {
            firstExpression= ((FieldAccess)firstExpression).getExpression();
        }
        if (!(firstExpression instanceof SimpleName))
            return;

        node= (SimpleName)firstExpression;
    } else if (firstExpression instanceof SuperFieldAccess)
        return;

    StructuralPropertyDescriptor parentDescription= node.getLocationInParent();
    if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY || parentDescription == SwitchCase.EXPRESSION_PROPERTY)
        return;

    IBinding binding= node.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return;

    handleVariable(node, (IVariableBinding) binding);
}
项目:Eclipse-Postfix-Code-Completion    文件:ImplementOccurrencesFinder.java   
public String initialize(CompilationUnit root, ASTNode node) {
    if (!(node instanceof Name))
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    fSelectedNode= ASTNodes.getNormalizedNode(node);
    if (!(fSelectedNode instanceof Type))
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    StructuralPropertyDescriptor location= fSelectedNode.getLocationInParent();
    if (location != TypeDeclaration.SUPERCLASS_TYPE_PROPERTY && location != TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY && location != EnumDeclaration.SUPER_INTERFACE_TYPES_PROPERTY)
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    fSelectedType= ((Type)fSelectedNode).resolveBinding();
    if (fSelectedType == null)
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    fStart= fSelectedNode.getParent(); // type declaration
    fASTRoot= root;
    fDescription= Messages.format(SearchMessages.ImplementOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fSelectedType.getName()));

    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTResolving.java   
public static ITypeBinding guessBindingForTypeReference(ASTNode node) {
    StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
    if (locationInParent == QualifiedName.QUALIFIER_PROPERTY) {
        return null; // can't guess type for X.A
    }
if (locationInParent == SimpleType.NAME_PROPERTY ||
        locationInParent == NameQualifiedType.NAME_PROPERTY) {
        node= node.getParent();
    }
    ITypeBinding binding= Bindings.normalizeTypeBinding(getPossibleTypeBinding(node));
    if (binding != null) {
        if (binding.isWildcardType()) {
            return normalizeWildcardType(binding, true, node.getAST());
        }
    }
    return binding;
  }
项目:Eclipse-Postfix-Code-Completion    文件:ASTResolving.java   
public static BodyDeclaration findParentBodyDeclaration(ASTNode node, boolean treatModifiersOutside) {
    StructuralPropertyDescriptor lastLocation= null;

    while (node != null) {
        if (node instanceof BodyDeclaration) {
            BodyDeclaration decl= (BodyDeclaration) node;
            if (!treatModifiersOutside || lastLocation != decl.getModifiersProperty()) {
                return decl;
            }
            treatModifiersOutside= false;
        }
        lastLocation= node.getLocationInParent();
        node= node.getParent();
    }
    return (BodyDeclaration) node;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTResolving.java   
public static BodyDeclaration findParentBodyDeclaration(ASTNode node, boolean treatModifiersOutside) {
    StructuralPropertyDescriptor lastLocation= null;

    while (node != null) {
        if (node instanceof BodyDeclaration) {
            BodyDeclaration decl= (BodyDeclaration) node;
            if (!treatModifiersOutside || lastLocation != decl.getModifiersProperty()) {
                return decl;
            }
            treatModifiersOutside= false;
        }
        lastLocation= node.getLocationInParent();
        node= node.getParent();
    }
    return (BodyDeclaration) node;
}
项目:Eclipse-Postfix-Code-Completion    文件:QuickAssistProcessor.java   
private static <T extends ASTNode> T getEnclosingHeader(ASTNode node, Class<T> headerType, StructuralPropertyDescriptor... headerProperties) {
    if (headerType.isInstance(node))
        return headerType.cast(node);

    while (node != null) {
        ASTNode parent= node.getParent();
        if (headerType.isInstance(parent)) {
            StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
            for (StructuralPropertyDescriptor property : headerProperties) {
                if (locationInParent == property)
                    return headerType.cast(parent);
            }
            return null;
        }
        node= parent;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RewriteEventStore.java   
public void addEvent(ASTNode parent, StructuralPropertyDescriptor childProperty, RewriteEvent event) {
    validateHasChildProperty(parent, childProperty);

    if (event.isListRewrite()) {
        validateIsListProperty(childProperty);
    }

    EventHolder holder= new EventHolder(parent, childProperty, event);

    List entriesList = (List) this.eventLookup.get(parent);
    if (entriesList != null) {
        for (int i= 0; i < entriesList.size(); i++) {
            EventHolder curr= (EventHolder) entriesList.get(i);
            if (curr.childProperty == childProperty) {
                entriesList.set(i, holder);
                this.lastEvent= null;
                return;
            }
        }
    } else {
        entriesList= new ArrayList(3);
        this.eventLookup.put(parent, entriesList);
    }
    entriesList.add(holder);
}
项目:Eclipse-Postfix-Code-Completion    文件:RewriteEventStore.java   
public RewriteEvent getEvent(ASTNode parent, StructuralPropertyDescriptor property) {
    validateHasChildProperty(parent, property);

    if (this.lastEvent != null && this.lastEvent.parent == parent && this.lastEvent.childProperty == property) {
        return this.lastEvent.event;
    }

    List entriesList = (List) this.eventLookup.get(parent);
    if (entriesList != null) {
        for (int i= 0; i < entriesList.size(); i++) {
            EventHolder holder= (EventHolder) entriesList.get(i);
            if (holder.childProperty == property) {
                this.lastEvent= holder;
                return holder.event;
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RewriteEventStore.java   
public RewriteEvent getEvent(ASTNode parent, StructuralPropertyDescriptor property) {
    validateHasChildProperty(parent, property);

    if (this.lastEvent != null && this.lastEvent.parent == parent && this.lastEvent.childProperty == property) {
        return this.lastEvent.event;
    }

    List entriesList = (List) this.eventLookup.get(parent);
    if (entriesList != null) {
        for (int i= 0; i < entriesList.size(); i++) {
            EventHolder holder= (EventHolder) entriesList.get(i);
            if (holder.childProperty == property) {
                this.lastEvent= holder;
                return holder.event;
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTResolving.java   
/**
 * Finds the parent type of a node.
 *
 * @param node the node inside the type to find
 * @param treatModifiersOutside if set, modifiers are not part of their type, but of the type's parent
 * @return returns either a AbstractTypeDeclaration or an AnonymousTypeDeclaration
 */
public static ASTNode findParentType(ASTNode node, boolean treatModifiersOutside) {
    StructuralPropertyDescriptor lastLocation= null;

    while (node != null) {
        if (node instanceof AbstractTypeDeclaration) {
            AbstractTypeDeclaration decl= (AbstractTypeDeclaration) node;
            if (!treatModifiersOutside || lastLocation != decl.getModifiersProperty()) {
                return decl;
            }
        } else if (node instanceof AnonymousClassDeclaration) {
            return node;
        }
        lastLocation= node.getLocationInParent();
        node= node.getParent();
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:InternalASTRewrite.java   
void postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property) {
    if(property.isChildListProperty()) {

        ListRewriteEvent event = getListEvent(node, property);
        List list = (List)node.getStructuralProperty(property);
        int i = list.indexOf(child);
        int s = list.size();
        int index;
        if(i + 1 < s) {
            ASTNode nextNode = (ASTNode)list.get(i + 1);
            index = event.getIndex(nextNode, ListRewriteEvent.NEW);
        } else {
            index = -1;
        }
        event.insert(child, index);
        if(child != null) {
            markAsMoveOrCopyTarget(node, child);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IntroduceParameterObjectProcessor.java   
@Override
protected boolean shouldReport(IProblem problem, CompilationUnit cu) {
    if (!super.shouldReport(problem, cu))
        return false;
    ASTNode node= ASTNodeSearchUtil.getAstNode(cu, problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1);
    if (node instanceof Type) {
        Type type= (Type) node;
        if (problem.getID() == IProblem.UndefinedType && getClassName().equals(ASTNodes.getTypeName(type))) {
            return false;
        }
    }
    if (node instanceof Name) {
        Name name= (Name) node;
        if (problem.getID() == IProblem.ImportNotFound && getPackage().indexOf(name.getFullyQualifiedName()) != -1)
            return false;
        if (problem.getID() == IProblem.MissingTypeInMethod) {
            StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
            String[] arguments= problem.getArguments();
            if ((locationInParent == MethodInvocation.NAME_PROPERTY || locationInParent == SuperMethodInvocation.NAME_PROPERTY)
                    && arguments.length > 3
                    && arguments[3].endsWith(getClassName()))
                return false;
        }
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RefactoringAvailabilityTester.java   
private static ASTNode getInlineableMethodNode(ASTNode node, IJavaElement unit) {
    if (node == null)
        return null;
    switch (node.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
            StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
            if (locationInParent == MethodDeclaration.NAME_PROPERTY) {
                return node.getParent();
            } else if (locationInParent == MethodInvocation.NAME_PROPERTY
                    || locationInParent == SuperMethodInvocation.NAME_PROPERTY) {
                return unit instanceof ICompilationUnit ? node.getParent() : null; // don't start on invocations in binary
            }
            return null;
        case ASTNode.EXPRESSION_STATEMENT:
            node= ((ExpressionStatement)node).getExpression();
    }
    switch (node.getNodeType()) {
        case ASTNode.METHOD_DECLARATION:
            return node;
        case ASTNode.METHOD_INVOCATION:
        case ASTNode.SUPER_METHOD_INVOCATION:
        case ASTNode.CONSTRUCTOR_INVOCATION:
            return unit instanceof ICompilationUnit ? node : null; // don't start on invocations in binary
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IntroduceFactoryRefactoring.java   
/**
 * Finds and returns the <code>ASTNode</code> for the given source text
 * selection, if it is an entire constructor call or the class name portion
 * of a constructor call or constructor declaration, or null otherwise.
 * @param unit The compilation unit in which the selection was made
 * @param offset The textual offset of the start of the selection
 * @param length The length of the selection in characters
 * @return ClassInstanceCreation or MethodDeclaration
 */
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
    ASTNode node= ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
    if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION)
        return node;
    if (node.getNodeType() == ASTNode.METHOD_DECLARATION && ((MethodDeclaration)node).isConstructor())
        return node;
    // we have some sub node. Make sure its the right child of the parent
    StructuralPropertyDescriptor location= node.getLocationInParent();
    ASTNode parent= node.getParent();
    if (location == ClassInstanceCreation.TYPE_PROPERTY) {
        return parent;
    } else if (location == MethodDeclaration.NAME_PROPERTY && ((MethodDeclaration)parent).isConstructor()) {
        return parent;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTNodes.java   
public static ASTNode findParent(ASTNode node, StructuralPropertyDescriptor[][] pathes) {
    for (int p= 0; p < pathes.length; p++) {
        StructuralPropertyDescriptor[] path= pathes[p];
        ASTNode current= node;
        int d= path.length - 1;
        for (; d >= 0 && current != null; d--) {
            StructuralPropertyDescriptor descriptor= path[d];
            if (!descriptor.equals(current.getLocationInParent()))
                break;
            current= current.getParent();
        }
        if (d < 0)
            return current;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeStyleFix.java   
private void handleSimpleName(SimpleName node) {
    ASTNode firstExpression= node.getParent();
    if (firstExpression instanceof FieldAccess) {
        while (firstExpression instanceof FieldAccess) {
            firstExpression= ((FieldAccess)firstExpression).getExpression();
        }
        if (!(firstExpression instanceof SimpleName))
            return;

        node= (SimpleName)firstExpression;
    } else if (firstExpression instanceof SuperFieldAccess)
        return;

    StructuralPropertyDescriptor parentDescription= node.getLocationInParent();
    if (parentDescription == VariableDeclarationFragment.NAME_PROPERTY || parentDescription == SwitchCase.EXPRESSION_PROPERTY)
        return;

    IBinding binding= node.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return;

    handleVariable(node, (IVariableBinding) binding);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ImplementOccurrencesFinder.java   
public String initialize(CompilationUnit root, ASTNode node) {
    if (!(node instanceof Name))
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    fSelectedNode= ASTNodes.getNormalizedNode(node);
    if (!(fSelectedNode instanceof Type))
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    StructuralPropertyDescriptor location= fSelectedNode.getLocationInParent();
    if (location != TypeDeclaration.SUPERCLASS_TYPE_PROPERTY && location != TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY && location != EnumDeclaration.SUPER_INTERFACE_TYPES_PROPERTY)
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    fSelectedType= ((Type)fSelectedNode).resolveBinding();
    if (fSelectedType == null)
        return SearchMessages.ImplementOccurrencesFinder_invalidTarget;

    fStart= fSelectedNode.getParent(); // type declaration
    fASTRoot= root;
    fDescription= Messages.format(SearchMessages.ImplementOccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fSelectedType.getName()));

    return null;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
private void handleVariableBinding(ASTNode node, IVariableBinding variableBindig) {
    if (variableBindig == null) {
        StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
        //System.out.println(locationInParent.getId() + " has no variable binding");
    } else {
        this.onVariableAccess(node, variableBindig);
    }
}