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

项目:RefDiff    文件:BindingsRecoveryAstVisitor.java   
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
    Type fieldType = fieldDeclaration.getType();
    int fieldModifiers = fieldDeclaration.getModifiers();
    Visibility visibility = getVisibility(fieldModifiers);
    // boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
    boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
    List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        String fieldName = fragment.getName().getIdentifier();
        final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
        attribute.setStatic(isStatic);
        attribute.setVisibility(visibility);
        attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));

        Expression expression = fragment.getInitializer();
        if (expression != null) {
            //attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
            addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
        }
        attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
    }
    return true;
}
项目:code    文件:HeuristicOwnedVisitor.java   
@Override
public boolean visit(FieldDeclaration node) {

    int modifiers = node.getModifiers();
    if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
        List<VariableDeclarationFragment> fragments = node.fragments();
        for (VariableDeclarationFragment varDeclFrag : fragments) {
            IVariableBinding varBinding = varDeclFrag.resolveBinding();
            String enclosingClass = varBinding.getDeclaringClass().getQualifiedName();
            if(!varBinding.getType().isPrimitive() && !varBinding.getType().getQualifiedName().equals("java.lang.String")){
                final TACVariable fieldVar = new TACVariable(varBinding);
                if(!enclosingClass.equals(Config.MAINCLASS)){
                    context.addEncapsulatedVariable(fieldVar);
                }
            }
        }
    }
    return super.visit(node);
}
项目:code    文件:HeuristicOwnedVisitor.java   
@Override
public boolean visit(FieldDeclaration node) {

    int modifiers = node.getModifiers();
    if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
        List<VariableDeclarationFragment> fragments = node.fragments();
        for (VariableDeclarationFragment varDeclFrag : fragments) {
            IVariableBinding varBinding = varDeclFrag.resolveBinding();
            String enclosingClass = varBinding.getDeclaringClass().getQualifiedName();
            if(!varBinding.getType().isPrimitive() && !varBinding.getType().getQualifiedName().equals("java.lang.String")){
                final TACVariable fieldVar = new TACVariable(varBinding);
                if(!enclosingClass.equals(Config.MAINCLASS)){
                    context.addEncapsulatedVariable(fieldVar);
                }
            }
        }
    }
    return super.visit(node);
}
项目:jdt2famix    文件:InJavaImporter.java   
public Parameter ensureParameterFromSingleVariableDeclaration(SingleVariableDeclaration variableDeclaration,
        Method method) {
    String name = variableDeclaration.getName().toString();
    String qualifiedName = Famix.qualifiedNameOf(method) + NAME_SEPARATOR + name;
    if (parameters.has(qualifiedName)) 
        return parameters.named(qualifiedName);
    Parameter parameter = new Parameter();
    parameters.add(qualifiedName, parameter);
    parameter.setName(name);
    parameter.setParentBehaviouralEntity(method);
    parameter.setDeclaredType(ensureTypeFromDomType(variableDeclaration.getType()));
    IVariableBinding binding = variableDeclaration.resolveBinding();
    if (binding != null) {
        createAnnotationInstancesToEntityFromAnnotationBinding(parameter, binding.getAnnotations());
        //We only recover the final modifier
        if (Modifier.isFinal(binding.getModifiers())) parameter.addModifiers("final");
    }
    return parameter;
}
项目:BUILD_file_generator    文件:JavaSourceFileParser.java   
private static String decideRuleKind(ReferencedClassesParser parser, Set<String> dependencies) {
  CompilationUnit cu = parser.compilationUnit;
  if (cu.types().isEmpty()) {
    return "java_library";
  }
  AbstractTypeDeclaration topLevelClass = (AbstractTypeDeclaration) cu.types().get(0);
  if ((topLevelClass.getModifiers() & Modifier.ABSTRACT) != 0) {
    // Class is abstract, can't be a test.
    return "java_library";
  }

  // JUnit 4 tests
  if (parser.className.endsWith("Test") && dependencies.contains("org.junit.Test")) {
    return "java_test";
  }

  if (any(
      topLevelClass.bodyDeclarations(),
      d -> d instanceof MethodDeclaration && isMainMethod((MethodDeclaration) d))) {
    return "java_binary";
  }

  return "java_library";
}
项目:pandionj    文件:TagParser.java   
@Override
public boolean visit(FieldDeclaration node) {
    List fragments = node.fragments();
    for(Object o : fragments) {
        VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
        String varName = frag.getName().getIdentifier();
        int line = cunit.getLineNumber(frag.getStartPosition());
        ASTNode parent = node.getParent();
        Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit));
        TypeDeclaration dec = (TypeDeclaration) node.getParent();
        String qName = dec.getName().getFullyQualifiedName();
        PackageDeclaration packageDec = cunit.getPackage();
        if(packageDec != null)
            qName = packageDec.getName().getFullyQualifiedName() + "." + qName;
        String type = !Modifier.isStatic(node.getModifiers()) ? qName : null; 
        VariableTags tags = new VariableTags(varName, type, line, scope, true);
        variables.add(tags);
    }
    return false;
}
项目:pandionj    文件:Visitor.java   
@Override
public boolean visit(TypeDeclaration node) {
    System.out.println(node.getParent().getClass());
    if(info == null)
        info = new ClassInfo(node.resolveBinding().getQualifiedName(), VisibilityInfo.from(node));


    for(FieldDeclaration f : node.getFields()) {
        if(!Modifier.isStatic(f.getModifiers())) {
            for(Object o : f.fragments()) {
                VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
                info.addField(new FieldInfo(frag.getName().toString()));
            }
        }

    }

    return true;
}
项目:pandionj    文件:Visitor.java   
@Override
public boolean visit(MethodDeclaration node) {
    boolean instanceMember = !node.isConstructor() && !Modifier.isStatic(node.getModifiers());
    if(((TypeDeclaration) node.getParent()).isPackageMemberTypeDeclaration()) {
        AssignmentVisitor v = new AssignmentVisitor();
        node.accept(v);
        if(instanceMember) {
            MethodInfo m = new MethodInfo(
                    node.getName().getIdentifier(), 
                    VisibilityInfo.from(node), 
                    node.getReturnType2().resolveBinding().isParameterizedType() ? Object.class.toString() : node.getReturnType2().resolveBinding().getQualifiedName(), 
                            v.params,
                            v.containsFieldAssignments);
            info.addMethod(m);
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:ModifierCorrectionSubProcessor.java   
public static void installLinkedVisibilityProposals(LinkedProposalModel linkedProposalModel, ASTRewrite rewrite, List<IExtendedModifier> modifiers, boolean inInterface, String groupId) {
    ASTNode modifier = findVisibilityModifier(modifiers);
    if (modifier != null) {
        int selected = ((Modifier) modifier).getKeyword().toFlagValue();

        LinkedProposalPositionGroup positionGroup = linkedProposalModel.getPositionGroup(groupId, true);
        positionGroup.addPosition(rewrite.track(modifier), false);
        positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10));

        // add all others
        int[] flagValues = inInterface ? new int[] { Modifier.PUBLIC, 0 } : new int[] { Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE };
        for (int i = 0; i < flagValues.length; i++) {
            if (flagValues[i] != selected) {
                positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i));
            }
        }
    }
}
项目:eclipse.jdt.ls    文件:AbstractSerialVersionOperation.java   
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
    final ASTRewrite rewrite = cuRewrite.getASTRewrite();
    VariableDeclarationFragment fragment = null;
    for (int i = 0; i < fNodes.length; i++) {
        final ASTNode node = fNodes[i];

        final AST ast = node.getAST();

        fragment = ast.newVariableDeclarationFragment();
        fragment.setName(ast.newSimpleName(NAME_FIELD));

        final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
        declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
        declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

        if (!addInitializer(fragment, node)) {
            continue;
        }

        if (fragment.getInitializer() != null) {

            final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
            if (node instanceof AbstractTypeDeclaration) {
                rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
            } else if (node instanceof AnonymousClassDeclaration) {
                rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
            } else if (node instanceof ParameterizedType) {
                final ParameterizedType type = (ParameterizedType) node;
                final ASTNode parent = type.getParent();
                if (parent instanceof ClassInstanceCreation) {
                    final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
                    final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
                    if (anonymous != null) {
                        rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
                    }
                }
            } else {
                Assert.isTrue(false);
            }

            addLinkedPositions(rewrite, fragment, positionGroups);
        }

        final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
        if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
            final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
            declaration.setJavadoc(doc);
        }
    }
    if (fragment == null) {
        return;
    }

    positionGroups.setEndPosition(rewrite.track(fragment));
}
项目:eclipse.jdt.ls    文件:NewMethodCorrectionProposal.java   
private int getInterfaceMethodModifiers(ASTNode targetTypeDecl, boolean createAbstractMethod) {
    // for interface and annotation members copy the modifiers from an existing member
    if (targetTypeDecl instanceof TypeDeclaration) {
        TypeDeclaration type= (TypeDeclaration) targetTypeDecl;
        MethodDeclaration[] methodDecls= type.getMethods();
        if (methodDecls.length > 0) {
            if (createAbstractMethod) {
                for (MethodDeclaration methodDeclaration : methodDecls) {
                    IMethodBinding methodBinding= methodDeclaration.resolveBinding();
                    if (methodBinding != null && JdtFlags.isAbstract(methodBinding)) {
                        return methodDeclaration.getModifiers();
                    }
                }
            }
            return methodDecls[0].getModifiers() & Modifier.PUBLIC;
        }
        List<BodyDeclaration> bodyDecls= type.bodyDeclarations();
        if (bodyDecls.size() > 0) {
            return bodyDecls.get(0).getModifiers() & Modifier.PUBLIC;
        }
    }
    return 0;
}
项目:code    文件:Utils.java   
public static boolean isMethodCompatible(IMethodBinding methodBinding) {

    Options options = Options.getInstance();
    if (!options.includeConstructors()
            && (methodBinding.isConstructor() || methodBinding
                    .isDefaultConstructor())) {
        return false;
    }
    if (!options.includeStaticMethods()
            && Modifier.isStatic(methodBinding.getModifiers())) {
        return false;
    }

    return true;

}
项目:che    文件:InferTypeArgumentsTCModel.java   
public ParameterTypeVariable2 makeParameterTypeVariable(
    IMethodBinding methodBinding, int parameterIndex) {
  if (methodBinding == null) return null;
  TType type =
      getBoxedType(methodBinding.getParameterTypes()[parameterIndex], /*no boxing*/ null);
  if (type == null) return null;

  ParameterTypeVariable2 cv = new ParameterTypeVariable2(type, parameterIndex, methodBinding);
  ParameterTypeVariable2 storedCv = (ParameterTypeVariable2) storedCv(cv);
  if (storedCv == cv) {
    if (methodBinding.getDeclaringClass().isLocal()
        || Modifier.isPrivate(methodBinding.getModifiers())) fCuScopedConstraintVariables.add(cv);
    makeElementVariables(storedCv, type);
    makeArrayElementVariable(storedCv);
    if (fStoreToString)
      storedCv.setData(
          ConstraintVariable2.TO_STRING,
          "[Parameter("
              + parameterIndex
              + ","
              + Bindings.asString(methodBinding)
              + ")]"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  return storedCv;
}
项目:che    文件:BindingLabelProvider.java   
private static int getAdornmentFlags(IBinding binding) {
  int adornments = 0;
  final int modifiers = binding.getModifiers();
  if (Modifier.isAbstract(modifiers)) adornments |= JavaElementImageDescriptor.ABSTRACT;
  if (Modifier.isFinal(modifiers)) adornments |= JavaElementImageDescriptor.FINAL;
  if (Modifier.isStatic(modifiers)) adornments |= JavaElementImageDescriptor.STATIC;

  if (binding.isDeprecated()) adornments |= JavaElementImageDescriptor.DEPRECATED;

  if (binding instanceof IMethodBinding) {
    if (((IMethodBinding) binding).isConstructor())
      adornments |= JavaElementImageDescriptor.CONSTRUCTOR;
    if (Modifier.isSynchronized(modifiers)) adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
    if (Modifier.isNative(modifiers)) adornments |= JavaElementImageDescriptor.NATIVE;
    ITypeBinding type = ((IMethodBinding) binding).getDeclaringClass();
    if (type.isInterface() && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers))
      adornments |= JavaElementImageDescriptor.DEFAULT_METHOD;
    if (((IMethodBinding) binding).getDefaultValue() != null)
      adornments |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
  }
  if (binding instanceof IVariableBinding && ((IVariableBinding) binding).isField()) {
    if (Modifier.isTransient(modifiers)) adornments |= JavaElementImageDescriptor.TRANSIENT;
    if (Modifier.isVolatile(modifiers)) adornments |= JavaElementImageDescriptor.VOLATILE;
  }
  return adornments;
}
项目:che    文件:BindingLabelProvider.java   
private static ImageDescriptor getBaseImageDescriptor(IBinding binding, int flags) {
  if (binding instanceof ITypeBinding) {
    ITypeBinding typeBinding = (ITypeBinding) binding;
    if (typeBinding.isArray()) {
      typeBinding = typeBinding.getElementType();
    }
    if (typeBinding.isCapture()) {
      typeBinding.getWildcard();
    }
    return getTypeImageDescriptor(typeBinding.getDeclaringClass() != null, typeBinding, flags);
  } else if (binding instanceof IMethodBinding) {
    ITypeBinding type = ((IMethodBinding) binding).getDeclaringClass();
    int modifiers = binding.getModifiers();
    if (type.isEnum()
        && (!Modifier.isPublic(modifiers)
            && !Modifier.isProtected(modifiers)
            && !Modifier.isPrivate(modifiers))
        && ((IMethodBinding) binding).isConstructor()) return JavaPluginImages.DESC_MISC_PRIVATE;
    return getMethodImageDescriptor(binding.getModifiers());
  } else if (binding instanceof IVariableBinding)
    return getFieldImageDescriptor((IVariableBinding) binding);
  return JavaPluginImages.DESC_OBJS_UNKNOWN;
}
项目:che    文件:CallInliner.java   
@Override
public boolean visit(SimpleName node) {
  IBinding binding = node.resolveBinding();
  if (binding instanceof IVariableBinding) {
    int accessMode = fFormalArgument.getSimplifiedAccessMode();
    if (fFormalArgument.isFinal() && !Modifier.isFinal(binding.getModifiers())) {
      return setResult(false);
    }
    if (accessMode == FlowInfo.READ || accessMode == FlowInfo.UNUSED) return setResult(true);
    // from now on we only have write accesses.
    IVariableBinding vb = (IVariableBinding) binding;
    if (vb.isField()) return setResult(false);
    return setResult(
        fFlowInfo.hasAccessMode(fFlowContext, vb, FlowInfo.UNUSED | FlowInfo.WRITE));
  }
  return setResult(false);
}
项目:che    文件:ExtractConstantRefactoring.java   
private void computeConstantDeclarationLocation() throws JavaModelException {
  if (isDeclarationLocationComputed()) return;

  BodyDeclaration lastStaticDependency = null;
  Iterator<BodyDeclaration> decls =
      getContainingTypeDeclarationNode().bodyDeclarations().iterator();

  while (decls.hasNext()) {
    BodyDeclaration decl = decls.next();

    int modifiers;
    if (decl instanceof FieldDeclaration) modifiers = ((FieldDeclaration) decl).getModifiers();
    else if (decl instanceof Initializer) modifiers = ((Initializer) decl).getModifiers();
    else {
      continue; /* this declaration is not a field declaration
                or initializer, so the placement of the constant
                declaration relative to it does not matter */
    }

    if (Modifier.isStatic(modifiers) && depends(getSelectedExpression(), decl))
      lastStaticDependency = decl;
  }

  if (lastStaticDependency == null) fInsertFirst = true;
  else fToInsertAfter = lastStaticDependency;
}
项目:j2objc    文件:OcniExtractor.java   
@Override
public void endVisit(MethodDeclaration node) {
  int modifiers = node.getModifiers();
  if (Modifier.isNative(modifiers)) {
    String nativeCode = extractNativeCode(node);
    if (nativeCode != null) {
      Block body = new Block();
      body.getStatements().add(new NativeStatement(nativeCode));
      node.setBody(body);
      node.removeModifiers(Modifier.NATIVE);
    }
  }
  if (Modifier.isSynchronized(modifiers)) {
    ITypeBinding declaringClass = node.getMethodBinding().getDeclaringClass();
    SynchronizedStatement syncStmt = new SynchronizedStatement(
        Modifier.isStatic(modifiers) ? new TypeLiteral(declaringClass)
        : new ThisExpression(declaringClass));
    syncStmt.setBody(TreeUtil.remove(node.getBody()));
    Block newBody = new Block();
    newBody.getStatements().add(syncStmt);
    node.setBody(newBody);
    node.removeModifiers(Modifier.SYNCHRONIZED);
  }
}
项目:j2objc    文件:InnerClassExtractor.java   
private GeneratedVariableBinding addParameter(
    MethodDeclaration constructor, ITypeBinding paramType, String name, int idx) {
  GeneratedMethodBinding constructorBinding =
      new GeneratedMethodBinding(constructor.getMethodBinding().getMethodDeclaration());
  constructor.setMethodBinding(constructorBinding);
  GeneratedVariableBinding paramBinding = new GeneratedVariableBinding(
      name, Modifier.FINAL, paramType, false, true, constructorBinding.getDeclaringClass(),
      constructorBinding);
  SingleVariableDeclaration paramNode = new SingleVariableDeclaration(paramBinding);
  if (idx == -1) {
    constructor.getParameters().add(paramNode);
    constructorBinding.addParameter(paramType);
  } else {
    constructor.getParameters().add(idx, paramNode);
    constructorBinding.addParameter(idx, paramType);
  }
  return paramBinding;
}
项目:j2objc    文件:ArrayRewriter.java   
private MethodInvocation newSingleDimensionArrayInvocation(
    ITypeBinding arrayType, Expression dimensionExpr, boolean retainedResult) {
  ITypeBinding componentType = arrayType.getComponentType();
  IOSTypeBinding iosArrayBinding = Types.resolveArrayType(componentType);

  String selector = (retainedResult ? "newArray" : "array") + "WithLength:"
      + (componentType.isPrimitive() ? "" : "type:");
  IOSMethodBinding methodBinding = IOSMethodBinding.newMethod(
      selector, Modifier.PUBLIC | Modifier.STATIC, iosArrayBinding, iosArrayBinding);
  methodBinding.addParameter(Types.resolveJavaType("int"));
  if (!componentType.isPrimitive()) {
    methodBinding.addParameter(Types.getIOSClass());
  }
  MethodInvocation invocation =
      new MethodInvocation(methodBinding, new SimpleName(iosArrayBinding));

  // Add the array length argument.
  invocation.getArguments().add(dimensionExpr.copy());

  // Add the type argument for object arrays.
  if (!componentType.isPrimitive()) {
    invocation.getArguments().add(newTypeLiteral(componentType));
  }

  return invocation;
}
项目:jdt2famix    文件:InJavaImporter.java   
private void setUpMethodFromMethodBinding(Method method, IMethodBinding binding) {
    if (binding.isConstructor()) 
        method.setKind(CONSTRUCTOR_KIND);
    ITypeBinding returnType = binding.getReturnType();
    if ((returnType != null) && !(returnType.isPrimitive() && returnType.getName().equals("void")))
        //we do not want to set void as a return type
        method.setDeclaredType(ensureTypeFromTypeBinding(returnType));
    extractBasicModifiersFromBinding(binding.getModifiers(), method);
    if (Modifier.isStatic(binding.getModifiers()))
        method.setHasClassScope(true);
    try {
        IAnnotationBinding[] annotations = binding.getAnnotations();
        createAnnotationInstancesToEntityFromAnnotationBinding(method, annotations);
    } catch(NullPointerException e) {
        /* This happens in some very strange circumstances, likely due to missing dependencies.
         * The only solution I found was to catch the exception and log it and provide people
         * with a way to solve it by adding the missing dependencies to the import.
         */
        logNullBinding("annotation instances for method binding", Famix.qualifiedNameOf(method) , -1);
    }
}
项目:j2objc    文件:ReferenceGraph.java   
private void addFieldEdges() {
  for (ITypeBinding type : allTypes.values()) {
    for (IVariableBinding field : type.getDeclaredFields()) {
      ITypeBinding fieldType = getElementType(field.getType());
      if (!whitelist.containsField(field)
          && !whitelist.containsType(fieldType)
          && !fieldType.isPrimitive()
          && !Modifier.isStatic(field.getModifiers())
          // Exclude self-referential fields. (likely linked DS or delegate pattern)
          && !type.isAssignmentCompatible(fieldType)
          && !BindingUtil.isWeakReference(field)) {
        addEdge(Edge.newFieldEdge(type, field));
      }
    }
  }
}
项目:che    文件:PromoteTempToFieldRefactoring.java   
/**
 * Creates a new promote temp to field refactoring.
 *
 * @param declaration the variable declaration node to convert to a field
 */
public PromoteTempToFieldRefactoring(VariableDeclaration declaration) {
  Assert.isTrue(declaration != null);
  fTempDeclarationNode = declaration;
  IVariableBinding resolveBinding = declaration.resolveBinding();
  Assert.isTrue(
      resolveBinding != null && !resolveBinding.isParameter() && !resolveBinding.isField());

  ASTNode root = declaration.getRoot();
  Assert.isTrue(root instanceof CompilationUnit);
  fCompilationUnitNode = (CompilationUnit) root;

  IJavaElement input = fCompilationUnitNode.getJavaElement();
  Assert.isTrue(input instanceof ICompilationUnit);
  fCu = (ICompilationUnit) input;

  fSelectionStart = declaration.getStartPosition();
  fSelectionLength = declaration.getLength();

  fFieldName = ""; // $NON-NLS-1$
  fVisibility = Modifier.PRIVATE;
  fDeclareStatic = false;
  fDeclareFinal = false;
  fInitializeIn = INITIALIZE_IN_METHOD;
  fLinkedProposalModel = null;
}
项目:che    文件:SemanticHighlightings.java   
@Override
public boolean consumes(SemanticToken token) {
  SimpleName node = token.getNode();
  if (node.isDeclaration()) return false;

  IBinding binding = token.getBinding();
  boolean isAbstractMethod =
      binding != null
          && binding.getKind() == IBinding.METHOD
          && (binding.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
  if (!isAbstractMethod) return false;

  // filter out annotation value references
  if (binding != null) {
    ITypeBinding declaringType = ((IMethodBinding) binding).getDeclaringClass();
    if (declaringType.isAnnotation()) return false;
  }

  return true;
}
项目:che    文件:GetterSetterCorrectionSubProcessor.java   
private static IMethodBinding findGetter(ProposalParameter context) {
  ITypeBinding returnType = context.variableBinding.getType();
  String getterName =
      GetterSetterUtil.getGetterName(
          context.variableBinding,
          context.compilationUnit.getJavaProject(),
          null,
          isBoolean(context));
  ITypeBinding declaringType = context.variableBinding.getDeclaringClass();
  if (declaringType == null) return null;
  IMethodBinding getter =
      Bindings.findMethodInHierarchy(declaringType, getterName, new ITypeBinding[0]);
  if (getter != null
      && getter.getReturnType().isAssignmentCompatible(returnType)
      && Modifier.isStatic(getter.getModifiers())
          == Modifier.isStatic(context.variableBinding.getModifiers())) return getter;
  return null;
}
项目:che    文件:PromoteTempToFieldRefactoring.java   
/**
 * Creates a new promote temp to field refactoring.
 *
 * @param unit the compilation unit, or <code>null</code> if invoked by scripting
 * @param selectionStart start
 * @param selectionLength length
 */
public PromoteTempToFieldRefactoring(
    ICompilationUnit unit, int selectionStart, int selectionLength) {
  Assert.isTrue(selectionStart >= 0);
  Assert.isTrue(selectionLength >= 0);
  fSelectionStart = selectionStart;
  fSelectionLength = selectionLength;
  fCu = unit;

  fFieldName = ""; // $NON-NLS-1$
  fVisibility = Modifier.PRIVATE;
  fDeclareStatic = false;
  fDeclareFinal = false;
  fInitializeIn = INITIALIZE_IN_METHOD;
  fLinkedProposalModel = null;
}
项目:che    文件:StubUtility2.java   
private static IMethodBinding[] getDelegateCandidates(
    ITypeBinding binding, ITypeBinding hierarchy) {
  List<IMethodBinding> allMethods = new ArrayList<IMethodBinding>();
  boolean isInterface = binding.isInterface();
  IMethodBinding[] typeMethods = binding.getDeclaredMethods();
  for (int index = 0; index < typeMethods.length; index++) {
    final int modifiers = typeMethods[index].getModifiers();
    if (!typeMethods[index].isConstructor()
        && !Modifier.isStatic(modifiers)
        && (isInterface || Modifier.isPublic(modifiers))) {
      IMethodBinding result =
          Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
      if (result != null && Flags.isFinal(result.getModifiers())) continue;
      ITypeBinding[] parameterBindings = typeMethods[index].getParameterTypes();
      boolean upper = false;
      for (int offset = 0; offset < parameterBindings.length; offset++) {
        if (parameterBindings[offset].isWildcardType()
            && parameterBindings[offset].isUpperbound()) upper = true;
      }
      if (!upper) allMethods.add(typeMethods[index]);
    }
  }
  return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
项目:che    文件:StubUtility2.java   
private static void getOverridableMethods(
    AST ast, ITypeBinding superBinding, List<IMethodBinding> allMethods) {
  IMethodBinding[] methods = superBinding.getDeclaredMethods();
  for (int offset = 0; offset < methods.length; offset++) {
    final int modifiers = methods[offset].getModifiers();
    if (!methods[offset].isConstructor()
        && !Modifier.isStatic(modifiers)
        && !Modifier.isPrivate(modifiers)) {
      if (findOverridingMethod(methods[offset], allMethods) == null
          && !Modifier.isStatic(modifiers)) allMethods.add(methods[offset]);
    }
  }
  ITypeBinding[] superInterfaces = superBinding.getInterfaces();
  for (int index = 0; index < superInterfaces.length; index++) {
    getOverridableMethods(ast, superInterfaces[index], allMethods);
  }
}
项目:che    文件:UnimplementedCodeFix.java   
/** {@inheritDoc} */
@Override
public void rewriteAST(
    CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedProposalPositions)
    throws CoreException {
  AST ast = cuRewrite.getAST();
  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  Modifier newModifier = ast.newModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  TextEditGroup textEditGroup =
      createTextEditGroup(
          CorrectionMessages.UnimplementedCodeFix_TextEditGroup_label, cuRewrite);
  rewrite
      .getListRewrite(fTypeDeclaration, TypeDeclaration.MODIFIERS2_PROPERTY)
      .insertLast(newModifier, textEditGroup);

  LinkedProposalPositionGroup group =
      new LinkedProposalPositionGroup("modifier"); // $NON-NLS-1$
  group.addPosition(rewrite.track(newModifier), !linkedProposalPositions.hasLinkedPositions());
  linkedProposalPositions.addPositionGroup(group);
}
项目:che    文件:MemberVisibilityAdjustor.java   
private void adjustOutgoingVisibilityChain(final IMember member, final IProgressMonitor monitor)
    throws JavaModelException {

  if (!Modifier.isPublic(member.getFlags())) {
    final ModifierKeyword threshold =
        computeOutgoingVisibilityThreshold(fReferencing, member, monitor);
    if (member instanceof IMethod) {
      adjustOutgoingVisibility(
          member,
          threshold,
          RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning);
    } else if (member instanceof IField) {
      adjustOutgoingVisibility((IField) member, threshold);
    } else if (member instanceof IType) {
      adjustOutgoingVisibility(
          member,
          threshold,
          RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_type_warning);
    }
  }

  if (member.getDeclaringType() != null)
    adjustOutgoingVisibilityChain(member.getDeclaringType(), monitor);
}
项目:che    文件:ModifierCorrectionSubProcessor.java   
public static void installLinkedVisibilityProposals(
    LinkedProposalModel linkedProposalModel,
    ASTRewrite rewrite,
    List<IExtendedModifier> modifiers,
    boolean inInterface) {
  ASTNode modifier = findVisibilityModifier(modifiers);
  if (modifier != null) {
    int selected = ((Modifier) modifier).getKeyword().toFlagValue();

    LinkedProposalPositionGroup positionGroup =
        linkedProposalModel.getPositionGroup(KEY_MODIFIER, true);
    positionGroup.addPosition(rewrite.track(modifier), false);
    positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10));

    // add all others
    int[] flagValues =
        inInterface
            ? new int[] {Modifier.PUBLIC, 0}
            : new int[] {Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE};
    for (int i = 0; i < flagValues.length; i++) {
      if (flagValues[i] != selected) {
        positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i));
      }
    }
  }
}
项目:che    文件:ConstructorFromSuperclassProposal.java   
private ITypeBinding getEnclosingInstance() {
  ITypeBinding currBinding = fTypeNode.resolveBinding();
  if (currBinding == null || Modifier.isStatic(currBinding.getModifiers())) {
    return null;
  }
  ITypeBinding superBinding = currBinding.getSuperclass();
  if (superBinding == null
      || superBinding.getDeclaringClass() == null
      || Modifier.isStatic(superBinding.getModifiers())) {
    return null;
  }
  ITypeBinding enclosing = superBinding.getDeclaringClass();

  while (currBinding != null) {
    if (Bindings.isSuperType(enclosing, currBinding)) {
      return null; // enclosing in scope
    }
    if (Modifier.isStatic(currBinding.getModifiers())) {
      return null; // no more enclosing instances
    }
    currBinding = currBinding.getDeclaringClass();
  }
  return enclosing;
}
项目:BUILD_file_generator    文件:JavaSourceFileParser.java   
/**
 * Returns true iff 'methodDeclaration' represents a void static method named 'main' that takes a
 * single String[] parameter.
 */
private static boolean isMainMethod(MethodDeclaration methodDeclaration) {
  // Is it static?
  if ((methodDeclaration.getModifiers() & Modifier.STATIC) == 0) {
    return false;
  }
  // Does it return void?
  Type returnType = methodDeclaration.getReturnType2();
  if (!returnType.isPrimitiveType()) {
    return false;
  }
  if (((PrimitiveType) returnType).getPrimitiveTypeCode() != PrimitiveType.VOID) {
    return false;
  }
  // Is it called 'main'?
  if (!"main".equals(methodDeclaration.getName().getIdentifier())) {
    return false;
  }
  // Does it have a single parameter?
  if (methodDeclaration.parameters().size() != 1) {
    return false;
  }

  // Is the parameter's type String[]?
  SingleVariableDeclaration pt =
      getOnlyElement((List<SingleVariableDeclaration>) methodDeclaration.parameters());
  IVariableBinding vb = pt.resolveBinding();
  if (vb == null) {
    return false;
  }
  ITypeBinding tb = vb.getType();
  return tb != null && "java.lang.String[]".equals(tb.getQualifiedName());
}
项目:RefDiff    文件:BindingsRecoveryAstVisitor.java   
private Visibility getVisibility(int methodModifiers) {
    Visibility visibility;
    if ((methodModifiers & Modifier.PUBLIC) != 0)
        visibility = Visibility.PUBLIC;
    else if ((methodModifiers & Modifier.PROTECTED) != 0)
        visibility = Visibility.PROTECTED;
    else if ((methodModifiers & Modifier.PRIVATE) != 0)
        visibility = Visibility.PRIVATE;
    else
        visibility = Visibility.PACKAGE;
    return visibility;
}
项目:RefDiff    文件:BindingsRecoveryAstVisitor.java   
private Visibility getVisibility(int methodModifiers) {
    Visibility visibility;
    if ((methodModifiers & Modifier.PUBLIC) != 0)
        visibility = Visibility.PUBLIC;
    else if ((methodModifiers & Modifier.PROTECTED) != 0)
        visibility = Visibility.PROTECTED;
    else if ((methodModifiers & Modifier.PRIVATE) != 0)
        visibility = Visibility.PRIVATE;
    else
        visibility = Visibility.PACKAGE;
    return visibility;
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
private static String getModifier(IBinding ib) {
    if ((ib.getModifiers() & Modifier.PUBLIC) > 0)
        return Fact.PUBLIC;
    else if ((ib.getModifiers() & Modifier.PROTECTED) > 0)
        return Fact.PROTECTED;
    else if ((ib.getModifiers() & Modifier.PRIVATE) > 0)
        return Fact.PRIVATE;
    else
        return Fact.PACKAGE;
}
项目:SnowGraph    文件:JavaASTVisitor.java   
private static String getVisibility(TypeDeclaration decl) {
    int modifiers = decl.getModifiers();
    if (Modifier.isPrivate(modifiers))
        return "private";
    if (Modifier.isProtected(modifiers))
        return "protected";
    if (Modifier.isPublic(modifiers))
        return "public";
    return "package";
}
项目:SnowGraph    文件:JavaASTVisitor.java   
private static String getVisibility(MethodDeclaration decl) {
    int modifiers = decl.getModifiers();
    if (Modifier.isPrivate(modifiers))
        return "private";
    if (Modifier.isProtected(modifiers))
        return "protected";
    if (Modifier.isPublic(modifiers))
        return "public";
    return "package";
}
项目:SnowGraph    文件:JavaASTVisitor.java   
private static String getVisibility(FieldDeclaration decl) {
    int modifiers = decl.getModifiers();
    if (Modifier.isPrivate(modifiers))
        return "private";
    if (Modifier.isProtected(modifiers))
        return "protected";
    if (Modifier.isPublic(modifiers))
        return "public";
    return "package";
}
项目:SparkBuilderGenerator    文件:ClassFieldCollector.java   
private boolean isStatic(FieldDeclaration field) {
    List<IExtendedModifier> fieldModifiers = field.modifiers();
    return fieldModifiers.stream()
            .filter(modifier -> modifier instanceof Modifier)
            .filter(modifer -> ((Modifier) modifer).getKeyword().equals(ModifierKeyword.STATIC_KEYWORD))
            .findFirst()
            .isPresent();
}