org.eclipse.jdt.internal.compiler.env.AccessRestriction Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.env.AccessRestriction. 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 File: SourcepathDirectory.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) {
  Path javaFile = getFile(packageName, typeName);

  // Could be looking for a nested class, so try using outer class file name.
  // ASSUMPTION: '$' is ONLY used in a compiler generated class file names.
  if (javaFile == null && typeName.indexOf("$") > 0) {
    javaFile = getFile(packageName, typeName.split("\\$")[0]);
  }

  if (javaFile != null) {
    CompilationUnit cu = new ClasspathCompilationUnit(javaFile, encoding);
    return new NameEnvironmentAnswer(cu, accessRestriction);
  }
  return null;
}
 
Example #2
Source File: InteractiveUnresolvedTypeResolver.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void findCandidateTypes(final JvmDeclaredType contextType, final String typeSimpleName,
		IJavaSearchScope searchScope, final IAcceptor<JvmDeclaredType> acceptor) throws JavaModelException {
	BasicSearchEngine searchEngine = new BasicSearchEngine();
	final IVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, contextType);
	searchEngine.searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, typeSimpleName.toCharArray(),
			SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.TYPE, searchScope,
			new IRestrictedAccessTypeRequestor() {
				@Override
				public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
						char[][] enclosingTypeNames, String path, AccessRestriction access) {
					final String qualifiedTypeName = getQualifiedTypeName(packageName, enclosingTypeNames,
							simpleTypeName);
					if ((access == null
							|| (access.getProblemId() != IProblem.ForbiddenReference && !access.ignoreIfBetter()))
						&& !TypeFilter.isFiltered(packageName, simpleTypeName)) {
						JvmType importType = typeRefs.findDeclaredType(qualifiedTypeName, contextType.eResource());
						if (importType instanceof JvmDeclaredType
								&& contextualVisibilityHelper.isVisible((JvmDeclaredType) importType)) {
							acceptor.accept((JvmDeclaredType) importType);
						}
					}
				}
			}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
}
 
Example #3
Source File: CompilationUnitProblemFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add additional source types
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	// ensure to jump back to toplevel type for first one (could be a member)
	while (sourceTypes[0].getEnclosingType() != null) {
		sourceTypes[0] = sourceTypes[0].getEnclosingType();
	}

	CompilationResult result =
		new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this.options.maxProblemsPerUnit);
	
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259, build the compilation unit in its own sand box.
	final long savedComplianceLevel = this.options.complianceLevel;
	final long savedSourceLevel = this.options.sourceLevel;
	
	try {
		IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject();
		this.options.complianceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
		this.options.sourceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true));

		// need to hold onto this
		CompilationUnitDeclaration unit =
			SourceTypeConverter.buildCompilationUnit(
					sourceTypes,//sourceTypes[0] is always toplevel here
					SourceTypeConverter.FIELD_AND_METHOD // need field and methods
					| SourceTypeConverter.MEMBER_TYPE // need member types
					| SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization
					this.lookupEnvironment.problemReporter,
					result);

		if (unit != null) {
			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
			this.lookupEnvironment.completeTypeBindings(unit);
		}
	} finally {
		this.options.complianceLevel = savedComplianceLevel;
		this.options.sourceLevel = savedSourceLevel;
	}
}
 
Example #4
Source File: ClasspathDirectory.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) {
  try {
    Path classFile = getFile(packageName, typeName);
    if (classFile != null) {
      try (InputStream is = Files.newInputStream(classFile)) {
        return new NameEnvironmentAnswer(ClassFileReader.read(is, classFile.getFileName().toString(), false), accessRestriction);
      }
    }
  } catch (ClassFormatException | IOException e) {
    // treat as if type is missing
  }
  return null;
}
 
Example #5
Source File: DependencyClasspathEntry.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
protected AccessRestriction getAccessRestriction(String packageName) {
  if (exportedPackages != null && !exportedPackages.contains(packageName)) {
    AccessRule rule = new AccessRule(null /* pattern */, IProblem.ForbiddenReference, true /* keep looking for accessible type */);
    return new AccessRestriction(rule, AccessRestriction.COMMAND_LINE, getEntryName());
  }
  return null;
}
 
Example #6
Source File: ClasspathJar.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) {
  try {
    String qualifiedFileName = packageName + "/" + typeName + SUFFIX_STRING_class;
    ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedFileName);
    if (reader != null) {
      return new NameEnvironmentAnswer(reader, accessRestriction);
    }
  } catch (ClassFormatException | IOException e) {
    // treat as if class file is missing
  }
  return null;
}
 
Example #7
Source File: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final boolean isTypeUseDeprecated(TypeBinding type, Scope scope) {

		if (type.isArrayType()) {
			type = ((ArrayBinding) type).leafComponentType;
		}
		if (type.isBaseType())
			return false;

		ReferenceBinding refType = (ReferenceBinding) type;
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=397888
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
		if ((this.bits & ASTNode.InsideJavadoc) == 0  && refType instanceof TypeVariableBinding) {
			refType.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
		}
		// ignore references insing Javadoc comments
		if ((this.bits & ASTNode.InsideJavadoc) == 0 && refType.isOrEnclosedByPrivateType() && !scope.isDefinedInType(refType)) {
			// ignore cases where type is used from inside itself
			((ReferenceBinding)refType.erasure()).modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
		}

		if (refType.hasRestrictedAccess()) {
			AccessRestriction restriction = scope.environment().getAccessRestriction(type.erasure());
			if (restriction != null) {
				scope.problemReporter().forbiddenReference(type, this, restriction.classpathEntryType,
						restriction.classpathEntryName, restriction.getProblemId());
			}
		}

		// force annotations resolution before deciding whether the type may be deprecated
		refType.initializeDeprecatedAnnotationTagBits();

		if (!refType.isViewedAsDeprecated()) return false;

		// inside same unit - no report
		if (scope.isDefinedInSameUnit(refType)) return false;

		// if context is deprecated, may avoid reporting
		if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
		return true;
	}
 
Example #8
Source File: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final boolean isMethodUseDeprecated(MethodBinding method, Scope scope,
		boolean isExplicitUse) {
	// ignore references insing Javadoc comments
	if ((this.bits & ASTNode.InsideJavadoc) == 0 && method.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(method)) {
		// ignore cases where method is used from inside itself (e.g. direct recursions)
		method.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
	}

	// TODO (maxime) consider separating concerns between deprecation and access restriction.
	// 				 Caveat: this was not the case when access restriction funtion was added.
	if (isExplicitUse && (method.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) {
		// note: explicit constructors calls warnings are kept despite the 'new C1()' case (two
		//       warnings, one on type, the other on constructor), because of the 'super()' case.
		AccessRestriction restriction =
			scope.environment().getAccessRestriction(method.declaringClass.erasure());
		if (restriction != null) {
			scope.problemReporter().forbiddenReference(method, this,
					restriction.classpathEntryType, restriction.classpathEntryName,
					restriction.getProblemId());
		}
	}

	if (!method.isViewedAsDeprecated()) return false;

	// inside same unit - no report
	if (scope.isDefinedInSameUnit(method.declaringClass)) return false;

	// non explicit use and non explicitly deprecated - no report
	if (!isExplicitUse &&
			(method.modifiers & ClassFileConstants.AccDeprecated) == 0) {
		return false;
	}

	// if context is deprecated, may avoid reporting
	if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
	return true;
}
 
Example #9
Source File: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope, int filteredBits) {
	if ((this.bits & ASTNode.InsideJavadoc) == 0			// ignore references inside Javadoc comments 
			&& (filteredBits & IsStrictlyAssigned) == 0 	// ignore write access
			&& field.isOrEnclosedByPrivateType() 
			&& !scope.isDefinedInField(field)) 				// ignore cases where field is used from inside itself 
	{		
		if (((filteredBits & IsCompoundAssigned) != 0))
			// used, but usage may not be relevant
			field.original().compoundUseFlag++;
		else
			field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
	}

	if ((field.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) {
		AccessRestriction restriction =
			scope.environment().getAccessRestriction(field.declaringClass.erasure());
		if (restriction != null) {
			scope.problemReporter().forbiddenReference(field, this,
					restriction.classpathEntryType, restriction.classpathEntryName,
					restriction.getProblemId());
		}
	}

	if (!field.isViewedAsDeprecated()) return false;

	// inside same unit - no report
	if (scope.isDefinedInSameUnit(field.declaringClass)) return false;

	// if context is deprecated, may avoid reporting
	if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
	return true;
}
 
Example #10
Source File: SearchableEnvironmentRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IJavaElementRequestor
 */
public void acceptType(IType type) {
	try {
		if (this.unitToSkip != null && this.unitToSkip.equals(type.getCompilationUnit())){
			return;
		}
		char[] packageName = type.getPackageFragment().getElementName().toCharArray();
		boolean isBinary = type instanceof BinaryType;

		// determine associated access restriction
		AccessRestriction accessRestriction = null;

		if (this.checkAccessRestrictions && (isBinary || !type.getJavaProject().equals(this.project))) {
			PackageFragmentRoot root = (PackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
			ClasspathEntry entry = (ClasspathEntry) this.nameLookup.rootToResolvedEntries.get(root);
			if (entry != null) { // reverse map always contains resolved CP entry
				AccessRuleSet accessRuleSet = entry.getAccessRuleSet();
				if (accessRuleSet != null) {
					// TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly
					char[][] packageChars = CharOperation.splitOn('.', packageName);
					char[] fileWithoutExtension = type.getElementName().toCharArray();
					accessRestriction = accessRuleSet.getViolatedRestriction(CharOperation.concatWith(packageChars, fileWithoutExtension, '/'));
				}
			}
		}
		this.requestor.acceptType(packageName, type.getElementName().toCharArray(), null, type.getFlags(), accessRestriction);
	} catch (JavaModelException jme) {
		// ignore
	}
}
 
Example #11
Source File: NameLookup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private AccessRestriction getViolatedRestriction(String typeName, String packageName, IType type, AccessRestriction accessRestriction) {
	PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
	ClasspathEntry entry = (ClasspathEntry) this.rootToResolvedEntries.get(root);
	if (entry != null) { // reverse map always contains resolved CP entry
		AccessRuleSet accessRuleSet = entry.getAccessRuleSet();
		if (accessRuleSet != null) {
			// TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly
			char[][] packageChars = CharOperation.splitOn('.', packageName.toCharArray());
			char[] typeChars = typeName.toCharArray();
			accessRestriction = accessRuleSet.getViolatedRestriction(CharOperation.concatWith(packageChars, typeChars, '/'));
		}
	}
	return accessRestriction;
}
 
Example #12
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add additional source types
 * @param sourceTypes
 * @param packageBinding
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	IProgressMonitor progressMonitor = this.builder.hierarchy.progressMonitor;
	if (progressMonitor != null && progressMonitor.isCanceled())
		throw new OperationCanceledException();

	// find most enclosing type first (needed when explicit askForType(...) is done
	// with a member type (e.g. p.A$B))
	ISourceType sourceType = sourceTypes[0];
	while (sourceType.getEnclosingType() != null)
		sourceType = sourceType.getEnclosingType();

	// build corresponding compilation unit
	CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
	CompilationUnitDeclaration unit =
		SourceTypeConverter.buildCompilationUnit(
			new ISourceType[] {sourceType}, // ignore secondary types, to improve laziness
			SourceTypeConverter.MEMBER_TYPE | (this.lookupEnvironment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8 ? SourceTypeConverter.METHOD : 0), // need member types
			// no need for field initialization
			this.lookupEnvironment.problemReporter,
			result);

	// build bindings
	if (unit != null) {
		try {
			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);

			org.eclipse.jdt.core.ICompilationUnit cu = ((SourceTypeElementInfo)sourceType).getHandle().getCompilationUnit();
			rememberAllTypes(unit, cu, false);

			this.lookupEnvironment.completeTypeBindings(unit, true/*build constructor only*/);
		} catch (AbortCompilation e) {
			// missing 'java.lang' package: ignore
		}
	}
}
 
Example #13
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add an additional compilation unit.
 * @param sourceUnit
 */
public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) {
	//System.out.println("Cannot accept compilation units inside the HierarchyResolver.");
	this.lookupEnvironment.problemReporter.abortDueToInternalError(
		new StringBuffer(Messages.accept_cannot)
			.append(sourceUnit.getFileName())
			.toString());
}
 
Example #14
Source File: SearchEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
	if (Flags.isInterface(modifiers)) {
		this.nameRequestor.acceptInterface(packageName, simpleTypeName, enclosingTypeNames, path);
	} else {
		this.nameRequestor.acceptClass(packageName, simpleTypeName, enclosingTypeNames, path);
	}
}
 
Example #15
Source File: IRestrictedAccessConstructorRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void acceptConstructor(
int modifiers,
char[] simpleTypeName,
int parameterCount,
char[] signature,
char[][] parameterTypes,
char[][] parameterNames,
int typeModifiers,
char[] packageName,
int extraFlags,
String path,
AccessRestriction access);
 
Example #16
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add an additional binary type
 * @param binaryType
 * @param packageBinding
 */
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	IProgressMonitor progressMonitor = this.builder.hierarchy.progressMonitor;
	if (progressMonitor != null && progressMonitor.isCanceled())
		throw new OperationCanceledException();

	BinaryTypeBinding typeBinding = this.lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction);
	try {
		this.remember(binaryType, typeBinding);
	} catch (AbortCompilation e) {
		// ignore
	}
}
 
Example #17
Source File: ISearchRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void acceptConstructor(
int modifiers,
char[] simpleTypeName,
int parameterCount,
char[] signature,
char[][] parameterTypes,
char[][] parameterNames,
int typeModifiers,
char[] packageName,
int extraFlags,
String path,
AccessRestriction access);
 
Example #18
Source File: SourceIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	ISourceType sourceType = sourceTypes[0];
	while (sourceType.getEnclosingType() != null)
		sourceType = sourceType.getEnclosingType();
	SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
	IType type = elementInfo.getHandle();
	ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
	accept(sourceUnit, accessRestriction);		
}
 
Example #19
Source File: EclipseFileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
protected void addNewEntry(ArrayList paths, String currentClasspathName,
		ArrayList currentRuleSpecs, String customEncoding,
		String destPath, boolean isSourceOnly,
		boolean rejectDestinationPathOnJars) {

	int rulesSpecsSize = currentRuleSpecs.size();
	AccessRuleSet accessRuleSet = null;
	if (rulesSpecsSize != 0) {
		AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()];
		boolean rulesOK = true;
		Iterator i = currentRuleSpecs.iterator();
		int j = 0;
		while (i.hasNext()) {
			String ruleSpec = (String) i.next();
			char key = ruleSpec.charAt(0);
			String pattern = ruleSpec.substring(1);
			if (pattern.length() > 0) {
				switch (key) {
					case '+':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(), 0);
						break;
					case '~':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.DiscouragedReference);
						break;
					case '-':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.ForbiddenReference);
						break;
					case '?':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.ForbiddenReference, true/*keep looking for accessible type*/);
						break;
					default:
						rulesOK = false;
				}
			} else {
				rulesOK = false;
			}
		}
		if (rulesOK) {
    		accessRuleSet = new AccessRuleSet(accessRules, AccessRestriction.COMMAND_LINE, currentClasspathName);
		} else {
			return;
		}
	}
	if (Main.NONE.equals(destPath)) {
		destPath = Main.NONE; // keep == comparison valid
	}
	if (rejectDestinationPathOnJars && destPath != null &&
			(currentClasspathName.endsWith(".jar") || //$NON-NLS-1$
				currentClasspathName.endsWith(".zip"))) { //$NON-NLS-1$
		throw new IllegalArgumentException(
				this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$
							currentClasspathName));
		}
	FileSystem.Classpath currentClasspath = FileSystem.getClasspath(
			currentClasspathName,
			customEncoding,
			isSourceOnly,
			accessRuleSet,
			destPath);
	if (currentClasspath != null) {
		paths.add(currentClasspath);
	}
}
 
Example #20
Source File: EclipseFileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
protected void addNewEntry(ArrayList paths, String currentClasspathName,
		ArrayList currentRuleSpecs, String customEncoding,
		String destPath, boolean isSourceOnly,
		boolean rejectDestinationPathOnJars) {

	int rulesSpecsSize = currentRuleSpecs.size();
	AccessRuleSet accessRuleSet = null;
	if (rulesSpecsSize != 0) {
		AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()];
		boolean rulesOK = true;
		Iterator i = currentRuleSpecs.iterator();
		int j = 0;
		while (i.hasNext()) {
			String ruleSpec = (String) i.next();
			char key = ruleSpec.charAt(0);
			String pattern = ruleSpec.substring(1);
			if (pattern.length() > 0) {
				switch (key) {
					case '+':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(), 0);
						break;
					case '~':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.DiscouragedReference);
						break;
					case '-':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.ForbiddenReference);
						break;
					case '?':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.ForbiddenReference, true/*keep looking for accessible type*/);
						break;
					default:
						rulesOK = false;
				}
			} else {
				rulesOK = false;
			}
		}
		if (rulesOK) {
    		accessRuleSet = new AccessRuleSet(accessRules, AccessRestriction.COMMAND_LINE, currentClasspathName);
		} else {
			return;
		}
	}
	if (Main.NONE.equals(destPath)) {
		destPath = Main.NONE; // keep == comparison valid
	}
	if (rejectDestinationPathOnJars && destPath != null &&
			(currentClasspathName.endsWith(".jar") || //$NON-NLS-1$
				currentClasspathName.endsWith(".zip"))) { //$NON-NLS-1$
		throw new IllegalArgumentException(
				this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$
							currentClasspathName));
		}
	FileSystem.Classpath currentClasspath = FileSystem.getClasspath(
			currentClasspathName,
			customEncoding,
			isSourceOnly,
			accessRuleSet,
			destPath);
	if (currentClasspath != null) {
		paths.add(currentClasspath);
	}
}
 
Example #21
Source File: AccessRestrictionClasspathEntry.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
public static AccessRestrictionClasspathEntry forbidAll(DependencyClasspathEntry entry) {
  AccessRule accessRule = new AccessRule(null /* pattern */, IProblem.ForbiddenReference, true /* keep looking for accessible type */);
  AccessRestriction accessRestriction = new AccessRestriction(accessRule, AccessRestriction.COMMAND_LINE, entry.getEntryName());
  return new AccessRestrictionClasspathEntry(entry, accessRestriction);
}
 
Example #22
Source File: AccessRestrictionClasspathEntry.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
private AccessRestrictionClasspathEntry(DependencyClasspathEntry entry, AccessRestriction accessRestriction) {
  this.entry = entry;
  this.accessRestriction = accessRestriction;
}
 
Example #23
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void buildMemberTypes(AccessRestriction accessRestriction) {
    SourceTypeBinding sourceType = this.referenceContext.binding;
	ReferenceBinding[] memberTypeBindings = Binding.NO_MEMBER_TYPES;
	if (this.referenceContext.memberTypes != null) {
		int length = this.referenceContext.memberTypes.length;
		memberTypeBindings = new ReferenceBinding[length];
		int count = 0;
		nextMember : for (int i = 0; i < length; i++) {
			TypeDeclaration memberContext = this.referenceContext.memberTypes[i];
			switch(TypeDeclaration.kind(memberContext.modifiers)) {
				case TypeDeclaration.INTERFACE_DECL :
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
					if (sourceType.isNestedType()
							&& sourceType.isClass() // no need to check for enum, since implicitly static
							&& !sourceType.isStatic()) {
						problemReporter().illegalLocalTypeDeclaration(memberContext);
						continue nextMember;
					}
				break;
			}
			ReferenceBinding type = sourceType;
			// check that the member does not conflict with an enclosing type
			do {
				if (CharOperation.equals(type.sourceName, memberContext.name)) {
					problemReporter().typeCollidesWithEnclosingType(memberContext);
					continue nextMember;
				}
				type = type.enclosingType();
			} while (type != null);
			// check that the member type does not conflict with another sibling member type
			for (int j = 0; j < i; j++) {
				if (CharOperation.equals(this.referenceContext.memberTypes[j].name, memberContext.name)) {
					problemReporter().duplicateNestedType(memberContext);
					continue nextMember;
				}
			}

			ClassScope memberScope = new ClassScope(this, memberContext);
			memberTypeBindings[count++] = memberScope.buildType(sourceType, sourceType.fPackage, accessRestriction);
		}
		if (count != length)
			System.arraycopy(memberTypeBindings, 0, memberTypeBindings = new ReferenceBinding[count], 0, count);
	}
	sourceType.setMemberTypes(memberTypeBindings);
}
 
Example #24
Source File: SourceIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	this.lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction);
}
 
Example #25
Source File: SourceIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void accept(ICompilationUnit unit, AccessRestriction accessRestriction) {
	CompilationResult unitResult = new CompilationResult(unit, 1, 1, this.options.maxProblemsPerUnit);
	CompilationUnitDeclaration parsedUnit = this.basicParser.dietParse(unit, unitResult);
	this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction);
	this.lookupEnvironment.completeTypeBindings(parsedUnit, true);
}
 
Example #26
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void addNewEntry(ArrayList paths, String currentClasspathName,
		ArrayList currentRuleSpecs, String customEncoding,
		String destPath, boolean isSourceOnly,
		boolean rejectDestinationPathOnJars) {

	int rulesSpecsSize = currentRuleSpecs.size();
	AccessRuleSet accessRuleSet = null;
	if (rulesSpecsSize != 0) {
		AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()];
		boolean rulesOK = true;
		Iterator i = currentRuleSpecs.iterator();
		int j = 0;
		while (i.hasNext()) {
			String ruleSpec = (String) i.next();
			char key = ruleSpec.charAt(0);
			String pattern = ruleSpec.substring(1);
			if (pattern.length() > 0) {
				switch (key) {
					case '+':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(), 0);
						break;
					case '~':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.DiscouragedReference);
						break;
					case '-':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.ForbiddenReference);
						break;
					case '?':
						accessRules[j++] = new AccessRule(pattern
								.toCharArray(),
								IProblem.ForbiddenReference, true/*keep looking for accessible type*/);
						break;
					default:
						rulesOK = false;
				}
			} else {
				rulesOK = false;
			}
		}
		if (rulesOK) {
    		accessRuleSet = new AccessRuleSet(accessRules, AccessRestriction.COMMAND_LINE, currentClasspathName);
		} else {
			if (currentClasspathName.length() != 0) {
				// we go on anyway
				addPendingErrors(this.bind("configure.incorrectClasspath", currentClasspathName));//$NON-NLS-1$
			}
			return;
		}
	}
	if (NONE.equals(destPath)) {
		destPath = NONE; // keep == comparison valid
	}
	if (rejectDestinationPathOnJars && destPath != null &&
			Util.isPotentialZipArchive(currentClasspathName)) {
		throw new IllegalArgumentException(
			this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$
						currentClasspathName));
	}
	FileSystem.Classpath currentClasspath = FileSystem.getClasspath(
			currentClasspathName,
			customEncoding,
			isSourceOnly,
			accessRuleSet,
			destPath);
	if (currentClasspath != null) {
		paths.add(currentClasspath);
	} else if (currentClasspathName.length() != 0) {
		// we go on anyway
		addPendingErrors(this.bind("configure.incorrectClasspath", currentClasspathName));//$NON-NLS-1$
	}
}
 
Example #27
Source File: CompilationUnitResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public synchronized void accept(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, AccessRestriction accessRestriction) {
	super.accept(sourceUnit, accessRestriction);
}
 
Example #28
Source File: CompilationUnitResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	// Need to reparse the entire source of the compilation unit so as to get source positions
	// (case of processing a source that was not known by beginToCompile (e.g. when asking to createBinding))
	SourceTypeElementInfo sourceType = (SourceTypeElementInfo) sourceTypes[0];
	accept((org.eclipse.jdt.internal.compiler.env.ICompilationUnit) sourceType.getHandle().getCompilationUnit(), accessRestriction);
}
 
Example #29
Source File: ClasspathEntry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
	 * Creates a class path entry of the specified kind with the given path.
	 */
	public ClasspathEntry(
		int contentKind,
		int entryKind,
		IPath path,
		IPath[] inclusionPatterns,
		IPath[] exclusionPatterns,
		IPath sourceAttachmentPath,
		IPath sourceAttachmentRootPath,
		IPath specificOutputLocation,
		IClasspathEntry referencingEntry,
		boolean isExported,
		IAccessRule[] accessRules,
		boolean combineAccessRules,
		IClasspathAttribute[] extraAttributes) {

		this.contentKind = contentKind;
		this.entryKind = entryKind;
		this.path = path;
		this.inclusionPatterns = inclusionPatterns;
		this.exclusionPatterns = exclusionPatterns;
		this.referencingEntry = referencingEntry;
		
		int length;
		if (accessRules != null && (length = accessRules.length) > 0) {
			AccessRule[] rules = new AccessRule[length];
			System.arraycopy(accessRules, 0, rules, 0, length);
			byte classpathEntryType;
			String classpathEntryName;
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
			if (this.entryKind == CPE_PROJECT || this.entryKind == CPE_SOURCE) { // can be remote source entry when reconciling
				classpathEntryType = AccessRestriction.PROJECT;
				classpathEntryName = manager.intern(getPath().segment(0));
			} else {
				classpathEntryType = AccessRestriction.LIBRARY;
				Object target = JavaModel.getWorkspaceTarget(path);
				if (target == null) {
					classpathEntryName = manager.intern(path.toOSString());
				} else {
					classpathEntryName = manager.intern(path.makeRelative().toString());
				}
			}
			this.accessRuleSet = new AccessRuleSet(rules, classpathEntryType, classpathEntryName);
		}
//		else { -- implicit!
//			this.accessRuleSet = null;
//		}

		this.combineAccessRules = combineAccessRules;
		this.extraAttributes = extraAttributes;

	    if (inclusionPatterns != INCLUDE_ALL && inclusionPatterns.length > 0) {
			this.fullInclusionPatternChars = UNINIT_PATTERNS;
	    }
	    if (exclusionPatterns.length > 0) {
			this.fullExclusionPatternChars = UNINIT_PATTERNS;
	    }
		this.sourceAttachmentPath = sourceAttachmentPath;
		this.sourceAttachmentRootPath = sourceAttachmentRootPath;
		this.specificOutputLocation = specificOutputLocation;
		this.isExported = isExported;
	}
 
Example #30
Source File: TypeNameRequestorWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
	this.requestor.acceptType(modifiers, packageName, simpleTypeName, enclosingTypeNames, path);
}