org.eclipse.jdt.core.dom.Modifier Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.Modifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: FindBrokenNLSKeysAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isPotentialNLSAccessor(ICompilationUnit unit) throws JavaModelException {
	IType type= unit.getTypes()[0];
	if (!type.exists())
		return false;

	IField bundleNameField= getBundleNameField(type.getFields());
	if (bundleNameField == null)
		return false;

	if (importsOSGIUtil(unit)) { //new school
		IInitializer[] initializers= type.getInitializers();
		for (int i= 0; i < initializers.length; i++) {
			if (Modifier.isStatic(initializers[0].getFlags()))
				return true;
		}
	} else { //old school
		IMethod[] methods= type.getMethods();
		for (int i= 0; i < methods.length; i++) {
			IMethod method= methods[i];
			if (isValueAccessor(method))
				return true;
		}
	}

	return false;
}
 
Example #2
@Override
boolean generateCandidates() {
	IVariableBinding[] fCandidateFields= fTypeBinding.getDeclaredFields();

	allFields= new ArrayList<IVariableBinding>();
	selectedFields= new ArrayList<IVariableBinding>();
	for (int i= 0; i < fCandidateFields.length; i++) {
		if (!Modifier.isStatic(fCandidateFields[i].getModifiers())) {
			allFields.add(fCandidateFields[i]);
			if (!Modifier.isTransient(fCandidateFields[i].getModifiers()))
				selectedFields.add(fCandidateFields[i]);
		}
	}
	if (allFields.isEmpty()) {
		return false;
	}
	return true;
}
 
Example #3
Source Project: JDeodorant   Author: tsantalis   File: ReplaceTypeCodeWithStateStrategy.java    License: MIT License 6 votes vote down vote up
private void createStateField() {
	ASTRewrite sourceRewriter = ASTRewrite.create(sourceTypeDeclaration.getAST());
	AST contextAST = sourceTypeDeclaration.getAST();
	ListRewrite contextBodyRewrite = sourceRewriter.getListRewrite(sourceTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
	VariableDeclarationFragment typeFragment = createStateFieldVariableDeclarationFragment(sourceRewriter, contextAST);
	
	FieldDeclaration typeFieldDeclaration = contextAST.newFieldDeclaration(typeFragment);
	sourceRewriter.set(typeFieldDeclaration, FieldDeclaration.TYPE_PROPERTY, contextAST.newSimpleName(abstractClassName), null);
	ListRewrite typeFieldDeclarationModifiersRewrite = sourceRewriter.getListRewrite(typeFieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
	typeFieldDeclarationModifiersRewrite.insertLast(contextAST.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD), null);
	contextBodyRewrite.insertBefore(typeFieldDeclaration, typeCheckElimination.getTypeField().getParent(), null);
	
	try {
		TextEdit sourceEdit = sourceRewriter.rewriteAST();
		ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement();
		CompilationUnitChange change = compilationUnitChanges.get(sourceICompilationUnit);
		change.getEdit().addChild(sourceEdit);
		change.addTextEditGroup(new TextEditGroup("Create field holding the current state", new TextEdit[] {sourceEdit}));
	} catch (JavaModelException e) {
		e.printStackTrace();
	}
}
 
Example #4
@Override
public boolean visit(final ClassInstanceCreation node) {
	Assert.isNotNull(node);
	if (fCreateInstanceField) {
		final AST ast= node.getAST();
		final Type type= node.getType();
		final ITypeBinding binding= type.resolveBinding();
		if (binding != null && binding.getDeclaringClass() != null && !Bindings.equals(binding, fTypeBinding) && fSourceRewrite.getRoot().findDeclaringNode(binding) != null) {
			if (!Modifier.isStatic(binding.getModifiers())) {
				Expression expression= null;
				if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
					final FieldAccess access= ast.newFieldAccess();
					access.setExpression(ast.newThisExpression());
					access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
					expression= access;
				} else
					expression= ast.newSimpleName(fEnclosingInstanceFieldName);
				if (node.getExpression() != null)
					fSourceRewrite.getImportRemover().registerRemovedNode(node.getExpression());
				fSourceRewrite.getASTRewrite().set(node, ClassInstanceCreation.EXPRESSION_PROPERTY, expression, fGroup);
			} else
				addTypeQualification(type, fSourceRewrite, fGroup);
		}
	}
	return true;
}
 
Example #5
Source Project: gwt-eclipse-plugin   Author: gwt-plugins   File: UiBinderJavaProblem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Set<UiBinderJavaProblem> createPrivateUiField(
    FieldDeclaration uiFieldDecl, Modifier privateModifier) {
  Set<UiBinderJavaProblem> problems = new HashSet<UiBinderJavaProblem>();

  List<VariableDeclarationFragment> varDecls = uiFieldDecl.fragments();
  for (VariableDeclarationFragment varDecl : varDecls) {
    String fieldName = varDecl.getName().getIdentifier();

    UiBinderJavaProblem problem = create(privateModifier,
        UiBinderJavaProblemType.PRIVATE_UI_FIELD, new String[] {fieldName},
        NO_STRINGS);
    if (problem != null) {
      problems.add(problem);
    }
  }

  return problems;
}
 
Example #6
Source Project: JDeodorant   Author: tsantalis   File: MoveMethodRefactoring.java    License: MIT License 6 votes vote down vote up
private void modifySourceStaticMethodInvocationsInTargetClass(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter) {
	ExpressionExtractor extractor = new ExpressionExtractor();	
	List<Expression> sourceMethodInvocations = extractor.getMethodInvocations(sourceMethod.getBody());
	List<Expression> newMethodInvocations = extractor.getMethodInvocations(newMethodDeclaration.getBody());
	int i = 0;
	for(Expression expression : sourceMethodInvocations) {
		if(expression instanceof MethodInvocation) {
			MethodInvocation methodInvocation = (MethodInvocation)expression;
			IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
			if((methodBinding.getModifiers() & Modifier.STATIC) != 0 &&
					methodBinding.getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding()) &&
					!additionalMethodsToBeMoved.containsKey(methodInvocation)) {
				AST ast = newMethodDeclaration.getAST();
				SimpleName qualifier = ast.newSimpleName(sourceTypeDeclaration.getName().getIdentifier());
				targetRewriter.set(newMethodInvocations.get(i), MethodInvocation.EXPRESSION_PROPERTY, qualifier, null);
				this.additionalTypeBindingsToBeImportedInTargetClass.add(sourceTypeDeclaration.resolveBinding());
			}
		}
		i++;
	}
}
 
Example #7
/**
 * Is the specified name a field access?
 *
 * @param name
 *            the name to check
 * @return <code>true</code> if this name is a field access,
 *         <code>false</code> otherwise
 */
protected static boolean isFieldAccess(final SimpleName name) {
	Assert.isNotNull(name);
	final IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return false;
	final IVariableBinding variable= (IVariableBinding) binding;
	if (!variable.isField())
		return false;
	if ("length".equals(name.getIdentifier())) { //$NON-NLS-1$
		final ASTNode parent= name.getParent();
		if (parent instanceof QualifiedName) {
			final QualifiedName qualified= (QualifiedName) parent;
			final ITypeBinding type= qualified.getQualifier().resolveTypeBinding();
			if (type != null && type.isArray())
				return false;
		}
	}
	return !Modifier.isStatic(variable.getModifiers());
}
 
Example #8
Source Project: eclipse.jdt.ls   Author: eclipse   File: ModifierCorrectionSubProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static int getNeededVisibility(ASTNode currNode, ITypeBinding targetType, IBinding binding) {
	ITypeBinding currNodeBinding = Bindings.getBindingOfParentType(currNode);
	if (currNodeBinding == null) { // import
		return Modifier.PUBLIC;
	}

	if (Bindings.isSuperType(targetType, currNodeBinding)) {
		if (binding != null && (JdtFlags.isProtected(binding) || binding.getKind() == IBinding.TYPE)) {
			return Modifier.PUBLIC;
		}
		return Modifier.PROTECTED;
	}

	if (currNodeBinding.getPackage().getKey().equals(targetType.getPackage().getKey())) {
		return 0;
	}
	return Modifier.PUBLIC;
}
 
Example #9
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	// TODO: update for fSelectionStart == -1
	final Map<String, String> arguments= new HashMap<String, String>();
	String project= null;
	IJavaProject javaProject= fSelectionTypeRoot.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	final IMethodBinding binding= fSourceProvider.getDeclaration().resolveBinding();
	int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	if (!Modifier.isPrivate(binding.getModifiers()))
		flags|= RefactoringDescriptor.MULTI_CHANGE;
	final String description= Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
	final String header= Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringClass(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
	if (!fTargetProvider.isSingle())
		comment.addSetting(RefactoringCoreMessages.ReplaceInvocationsRefactoring_replace_references);
	final JavaRefactoringDescriptor descriptor= new JavaRefactoringDescriptor(ID_REPLACE_INVOCATIONS, project, description, comment.asString(), arguments, flags){}; //REVIEW Unregistered ID!
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionTypeRoot));
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$
	arguments.put(ATTRIBUTE_MODE, new Integer(fTargetProvider.isSingle() ? 0 : 1).toString());
	return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ReplaceInvocationsRefactoring_change_name, fChangeManager.getAllChanges());
}
 
Example #10
public VariableVariable2 makeVariableVariable(IVariableBinding variableBinding) {
	if (variableBinding == null)
		return null;
	TType type= getBoxedType(variableBinding.getType(), /*no boxing*/null);
	if (type == null)
		return null;
	VariableVariable2 cv= new VariableVariable2(type, variableBinding);
	VariableVariable2 storedCv= (VariableVariable2) storedCv(cv);
	if (storedCv == cv) {
		if (! variableBinding.isField() || Modifier.isPrivate(variableBinding.getModifiers()))
			fCuScopedConstraintVariables.add(storedCv);
		makeElementVariables(storedCv, type);
		makeArrayElementVariable(storedCv);
		if (fStoreToString)
			storedCv.setData(ConstraintVariable2.TO_STRING, '[' + variableBinding.getName() + ']');
	}
	return storedCv;
}
 
Example #11
Source Project: jdt2famix   Author: feenkcom   File: InJavaImporter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * We pass both the fragment and the field because we need the field type when
 * the binding cannot be resolved
 */
public Attribute ensureAttributeForFragment(VariableDeclarationFragment fragment, FieldDeclaration field) {
	IVariableBinding binding = fragment.resolveBinding();
	Attribute attribute;
	if (binding == null)
		attribute = ensureAttributeFromFragmentIntoParentType(fragment, field,
				this.topFromContainerStack(Type.class));
	else {
		attribute = ensureAttributeForVariableBinding(binding);
		extractBasicModifiersFromBinding(binding.getModifiers(), attribute);
		if (Modifier.isStatic(binding.getModifiers()))
			attribute.setHasClassScope(true);
	}
	attribute.setIsStub(true);
	return attribute;
}
 
Example #12
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ASTResolving.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isVariableDefinedInContext(IBinding binding, ITypeBinding typeVariable) {
	if (binding.getKind() == IBinding.VARIABLE) {
		IVariableBinding var= (IVariableBinding) binding;
		binding= var.getDeclaringMethod();
		if (binding == null) {
			binding= var.getDeclaringClass();
		}
	}
	if (binding instanceof IMethodBinding) {
		if (binding == typeVariable.getDeclaringMethod()) {
			return true;
		}
		binding= ((IMethodBinding) binding).getDeclaringClass();
	}

	while (binding instanceof ITypeBinding) {
		if (binding == typeVariable.getDeclaringClass()) {
			return true;
		}
		if (Modifier.isStatic(binding.getModifiers())) {
			break;
		}
		binding= ((ITypeBinding) binding).getDeclaringClass();
	}
	return false;
}
 
Example #13
/**
 * Adds a new field to the {@link AST} using the given type and variable name. The method
 * returns a {@link TextEdit} which can then be applied using the {@link #applyTextEdit(TextEdit)} method.
 * 
 * @param type
 * @param varName
 * @return a {@link TextEdit} which represents the changes which would be made, or <code>null</code> if the field
 * can not be created.
 */
public TextEdit addField(String type, String varName, boolean publicField, boolean staticField, boolean finalField, String value) {
	
	if (isReadOnly())
		return null;

	if (!domInitialized)
		initDomAST();
	
	boolean isStatic = isBodyStatic();
	int modifiers = (!publicField) ? Modifier.PRIVATE : Modifier.PUBLIC;
	if (isStatic || staticField) {
		modifiers |= Modifier.STATIC;
	}
	if (finalField) {
		modifiers |= Modifier.FINAL;
	}
	
	ASTRewrite rewrite= ASTRewrite.create(parentDeclaration.getAST());
	
	VariableDeclarationFragment newDeclFrag = addFieldDeclaration(rewrite, parentDeclaration, modifiers, varName, type, value);

	TextEdit te = rewrite.rewriteAST(getDocument(), null);
	return te;
}
 
Example #14
private static Modifier findVisibilityModifier(List<IExtendedModifier> modifiers) {
	for (int i= 0; i < modifiers.size(); i++) {
		IExtendedModifier curr= modifiers.get(i);
		if (curr instanceof Modifier) {
			Modifier modifier= (Modifier) curr;
			ModifierKeyword keyword= modifier.getKeyword();
			if (keyword == ModifierKeyword.PUBLIC_KEYWORD || keyword == ModifierKeyword.PROTECTED_KEYWORD || keyword == ModifierKeyword.PRIVATE_KEYWORD) {
				return modifier;
			}
		}
	}
	return null;
}
 
Example #15
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: SourceActionDialog.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected Composite addVisibilityAndModifiersChoices(Composite buttonComposite) {
	// Add visibility and modifiers buttons: http://bugs.eclipse.org/bugs/show_bug.cgi?id=35870
	// Add persistence of options: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
	IVisibilityChangeListener visibilityChangeListener= new IVisibilityChangeListener(){
		public void visibilityChanged(int newVisibility) {
			setVisibility(newVisibility);
		}
		public void modifierChanged(int modifier, boolean isChecked) {
			switch (modifier) {
				case Modifier.FINAL:  {
					setFinal(isChecked);
					return;
				}
				case Modifier.SYNCHRONIZED:  {
					setSynchronized(isChecked);
					return;
				}
				default: return;
			}
		}
	};

	int initialVisibility= getVisibilityModifier();
	int[] availableVisibilities= new int[]{Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE, Modifier.NONE};

	Composite visibilityComposite= createVisibilityControlAndModifiers(buttonComposite, visibilityChangeListener, availableVisibilities, initialVisibility);
	return visibilityComposite;
}
 
Example #16
Source Project: eclipse-cs   Author: checkstyle   File: DesignForExtensionQuickfix.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
        final int markerStartOffset) {
  return new ASTVisitor() {

    @SuppressWarnings("unchecked")
    @Override
    public boolean visit(MethodDeclaration node) {
      // recalculate start position because optional javadoc is mixed
      // into the original start position
      int pos = node.getStartPosition() + (node.getJavadoc() != null
              ? node.getJavadoc().getLength() + JAVADOC_COMMENT_LENGTH
              : 0);
      if (containsPosition(lineInfo, pos)) {

        if (!Modifier.isFinal(node.getModifiers())) {

          Modifier finalModifier = node.getAST().newModifier(ModifierKeyword.FINAL_KEYWORD);
          node.modifiers().add(finalModifier);

          // reorder modifiers into their correct order
          List<ASTNode> reorderedModifiers = ModifierOrderQuickfix.reOrderModifiers(node.modifiers());
          node.modifiers().clear();
          node.modifiers().addAll(reorderedModifiers);
        }
      }
      return true;
    }
  };
}
 
Example #17
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: SurroundWith.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Makes the given statement final.
 * 
 * @param statement the statment
 * @param rewrite the AST rewrite
 */
protected static void makeFinal(VariableDeclarationStatement statement, ASTRewrite rewrite) {
	VariableDeclaration fragment= (VariableDeclaration)statement.fragments().get(0);
	if (ASTNodes.findModifierNode(Modifier.FINAL, ASTNodes.getModifiers(fragment)) == null) {
		ModifierRewrite.create(rewrite, statement).setModifiers(Modifier.FINAL, Modifier.NONE, null);
	}
}
 
Example #18
public void setVisibility(int accessModifier) {
	Assert.isTrue(accessModifier == Modifier.PRIVATE ||
					accessModifier == Modifier.NONE ||
					accessModifier == Modifier.PROTECTED ||
					accessModifier == Modifier.PUBLIC);
    fVisibility= accessModifier;
}
 
Example #19
private boolean isBindingToTemp(IVariableBinding variable) {
	if (variable.isField())
		return false;
	if (!Modifier.isFinal(variable.getModifiers()))
		return false;
	ASTNode declaringNode= fCompilationUnitNode.findDeclaringNode(variable);
	if (declaringNode == null)
		return false;
	if (ASTNodes.isParent(declaringNode, fAnonymousInnerClassNode))
		return false;
	return true;
}
 
Example #20
Source Project: j2cl   Author: google   File: JdtUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isStatic(IBinding binding) {
  if (binding instanceof IVariableBinding) {
    IVariableBinding variableBinding = (IVariableBinding) binding;
    if (!variableBinding.isField() || variableBinding.getDeclaringClass().isInterface()) {
      // Interface fields and variables are implicitly static.
      return true;
    }
  }
  return Modifier.isStatic(binding.getModifiers());
}
 
Example #21
Source Project: xtext-xtend   Author: eclipse   File: ASTFlattenerUtils.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public boolean isLambdaCase(final ClassInstanceCreation creation) {
  final AnonymousClassDeclaration anonymousClazz = creation.getAnonymousClassDeclaration();
  if (((anonymousClazz != null) && (anonymousClazz.bodyDeclarations().size() == 1))) {
    final Object declaredMethod = anonymousClazz.bodyDeclarations().get(0);
    if (((declaredMethod instanceof MethodDeclaration) && (creation.getType().resolveBinding() != null))) {
      final IMethodBinding methodBinding = ((MethodDeclaration) declaredMethod).resolveBinding();
      if ((methodBinding != null)) {
        final IMethodBinding overrides = this.findOverride(methodBinding, methodBinding.getDeclaringClass(), true);
        return ((overrides != null) && Modifier.isAbstract(overrides.getModifiers()));
      }
    }
  }
  return false;
}
 
Example #22
private static boolean isStaticAccess(SimpleName memberName) {
	IBinding binding= memberName.resolveBinding();
	Assert.isTrue(binding instanceof IVariableBinding || binding instanceof IMethodBinding || binding instanceof ITypeBinding);

	if (binding instanceof ITypeBinding)
		return true;

	if (binding instanceof IVariableBinding)
		return ((IVariableBinding) binding).isField();

	int modifiers= binding.getModifiers();
	return Modifier.isStatic(modifiers);
}
 
Example #23
Source Project: JDeodorant   Author: tsantalis   File: AbstractVariable.java    License: MIT License 5 votes vote down vote up
public AbstractVariable(VariableDeclaration name) {
	IVariableBinding variableBinding = name.resolveBinding();
	this.variableBindingKey = variableBinding.getKey();
	this.variableName = variableBinding.getName();
	this.variableType = variableBinding.getType().getQualifiedName();
	this.isField = variableBinding.isField();
	this.isParameter = variableBinding.isParameter();
	this.isStatic = (variableBinding.getModifiers() & Modifier.STATIC) != 0;
}
 
Example #24
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ASTNodeFactory.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a list of newly created Modifier nodes corresponding to a given list of existing modifiers.
 * @param ast The AST to create the nodes for.
 * @param modifierNodes The modifier nodes describing the modifier nodes to create. Only
 * nodes of type {@link Modifier} are looked at and cloned. To create a full copy of the list consider
 * to use {@link ASTNode#copySubtrees(AST, List)}.
 * @return Returns a list of nodes of type {@link Modifier}.
 */
public static List<Modifier> newModifiers(AST ast, List<? extends IExtendedModifier> modifierNodes) {
	List<Modifier> res= new ArrayList<Modifier>(modifierNodes.size());
	for (int i= 0; i < modifierNodes.size(); i++) {
		Object curr= modifierNodes.get(i);
		if (curr instanceof Modifier) {
			res.add(ast.newModifier(((Modifier) curr).getKeyword()));
		}
	}
	return res;
}
 
Example #25
private static boolean isVisibleFrom(IType newMemberDeclaringType, IType accessingType) throws JavaModelException {
	int memberVisibility= JdtFlags.getVisibilityCode(newMemberDeclaringType);

	IType declaringType= newMemberDeclaringType.getDeclaringType();
	while (declaringType != null) { //get lowest visibility in all parent types of newMemberDeclaringType
		memberVisibility= JdtFlags.getLowerVisibility(
				memberVisibility, JdtFlags.getVisibilityCode(declaringType));
		declaringType= declaringType.getDeclaringType();
	}

	switch (memberVisibility) {
		case Modifier.PRIVATE :
			return isEqualOrEnclosedType(accessingType, newMemberDeclaringType);

		case Modifier.NONE :
			return JavaModelUtil.isSamePackage(accessingType.getPackageFragment(), newMemberDeclaringType.getPackageFragment());

		case Modifier.PROTECTED :
			return JavaModelUtil.isSamePackage(accessingType.getPackageFragment(), newMemberDeclaringType.getPackageFragment())
					|| accessingType.newSupertypeHierarchy(null).contains(newMemberDeclaringType);

		case Modifier.PUBLIC :
			return true;

		default:
			Assert.isTrue(false);
			return false;
	}
}
 
Example #26
int getNewModifiersForCopyInSubclass(int oldModifiers) throws JavaModelException {
	if (isFieldInfo())
		return oldModifiers;
	if (isToBeDeletedFromDeclaringClass())
		return oldModifiers;
	int modifiers= oldModifiers;
	if (isNewMethodToBeDeclaredAbstract()) {
		if (!JdtFlags.isPublic(fMember))
			modifiers= Modifier.PROTECTED | JdtFlags.clearAccessModifiers(modifiers);
	}
	return modifiers;
}
 
Example #27
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: SemanticHighlightings.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	SimpleName node= token.getNode();
	if (node.isDeclaration())
		return false;

	IBinding binding= token.getBinding();
	return binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
}
 
Example #28
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;
}
 
Example #29
private int createModifiersForNestedClass() {
    int flags= fVisibility;
    if (fDeclareFinal)
        flags|= Modifier.FINAL;
    if (mustInnerClassBeStatic() || fDeclareStatic)
        flags|= Modifier.STATIC;
    return flags;
}
 
Example #30
Source Project: txtUML   Author: ELTE-Soft   File: ElementTypeTeller.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isFinal(FieldDeclaration node) {
	for (Object modifier : node.modifiers()) {
		if (modifier instanceof Modifier && ((Modifier) modifier).isFinal()) {
			return true;
		}
	}
	return false;
}