List of usage examples for org.eclipse.jdt.internal.compiler.env NameEnvironmentAnswer ignoreIfBetter
public boolean ignoreIfBetter()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.JavaSearchNameEnvironment.java
License:Open Source License
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) { String binaryFileName = null, qBinaryFileName = null, sourceFileName = null, qSourceFileName = null, qPackageName = null;// ww w . java 2 s. c o m NameEnvironmentAnswer suggestedAnswer = null; for (int i = 0, length = this.locations.length; i < length; i++) { ClasspathLocation location = this.locations[i]; NameEnvironmentAnswer answer; if (location instanceof ClasspathSourceDirectory) { if (sourceFileName == null) { qSourceFileName = qualifiedTypeName; // doesn't include the file extension sourceFileName = qSourceFileName; qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qSourceFileName.length() - typeName.length; qPackageName = qSourceFileName.substring(0, typeNameStart - 1); sourceFileName = qSourceFileName.substring(typeNameStart); } } ICompilationUnit workingCopy = (ICompilationUnit) this.workingCopies.get(qualifiedTypeName); if (workingCopy != null) { answer = new NameEnvironmentAnswer(workingCopy, null /*no access restriction*/); } else { answer = location.findClass(sourceFileName, // doesn't include the file extension qPackageName, qSourceFileName); // doesn't include the file extension } } else { if (binaryFileName == null) { qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class; binaryFileName = qBinaryFileName; qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class" qPackageName = qBinaryFileName.substring(0, typeNameStart - 1); binaryFileName = qBinaryFileName.substring(typeNameStart); } } answer = location.findClass(binaryFileName, qPackageName, qBinaryFileName); } if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer)) // remember suggestion and keep looking suggestedAnswer = answer; } } if (suggestedAnswer != null) // no better answer was found return suggestedAnswer; return null; }
From source file:io.takari.maven.plugins.compile.jdt.classpath.Classpath.java
License:Open Source License
private NameEnvironmentAnswer findType(String packageName, String typeName) { NameEnvironmentAnswer suggestedAnswer = null; Collection<ClasspathEntry> entries = !packageName.isEmpty() ? packages.get(packageName) : this.entries; if (entries != null) { String binaryFileName = typeName + SUFFIX_STRING_class; for (ClasspathEntry entry : entries) { NameEnvironmentAnswer answer = entry.findType(packageName, binaryFileName); if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) { return answer; }/* w w w . java2 s. c o m*/ } else if (answer.isBetter(suggestedAnswer)) { // remember suggestion and keep looking suggestedAnswer = answer; } } } } return suggestedAnswer; }
From source file:net.sf.j2s.core.builder.NameEnvironment.java
License:Open Source License
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) { if (this.notifier != null) this.notifier.checkCancelWithinCompiler(); if (this.initialTypeNames != null && this.initialTypeNames.includes(qualifiedTypeName)) { if (this.isIncrementalBuild) // catch the case that a type inside a source file has been renamed but other class files are looking for it throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedTypeName)); return null; // looking for a file which we know was provided at the beginning of the compilation }/* www. j av a 2s. c o m*/ if (this.additionalUnits != null && this.sourceLocations.length > 0) { // if an additional source file is waiting to be compiled, answer it BUT not if this is a secondary type search // if we answer X.java & it no longer defines Y then the binary type looking for Y will think the class path is wrong // let the recompile loop fix up dependents when the secondary type Y has been deleted from X.java // Only enclosing type names are present in the additional units table, so strip off inner class specifications // when doing the lookup (https://bugs.eclipse.org/372418). // Also take care of $ in the name of the class (https://bugs.eclipse.org/377401) // and prefer name with '$' if unit exists rather than failing to search for nested class (https://bugs.eclipse.org/392727) SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /*no access restriction*/); int index = qualifiedTypeName.indexOf('$'); if (index > 0) { String enclosingTypeName = qualifiedTypeName.substring(0, index); unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /*no access restriction*/); } } String qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class; String binaryFileName = qBinaryFileName; String qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class" qPackageName = qBinaryFileName.substring(0, typeNameStart - 1); binaryFileName = qBinaryFileName.substring(typeNameStart); } // NOTE: the output folders are added at the beginning of the binaryLocations NameEnvironmentAnswer suggestedAnswer = null; for (int i = 0, l = this.binaryLocations.length; i < l; i++) { NameEnvironmentAnswer answer = this.binaryLocations[i].findClass(binaryFileName, qPackageName, qBinaryFileName); if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer)) // remember suggestion and keep looking suggestedAnswer = answer; } } if (suggestedAnswer != null) // no better answer was found return suggestedAnswer; return null; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.JavaSearchNameEnvironment.java
License:Open Source License
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) { String binaryFileName = null, qBinaryFileName = null, sourceFileName = null, qSourceFileName = null, qPackageName = null;/*from ww w .ja va 2 s.co m*/ NameEnvironmentAnswer suggestedAnswer = null; for (int i = 0, length = this.locations.length; i < length; i++) { CodenvyClasspathLocation location = this.locations[i]; NameEnvironmentAnswer answer; if (location instanceof ClasspathSourceDirectory) { if (sourceFileName == null) { qSourceFileName = qualifiedTypeName; // doesn't include the file extension sourceFileName = qSourceFileName; qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qSourceFileName.length() - typeName.length; qPackageName = qSourceFileName.substring(0, typeNameStart - 1); sourceFileName = qSourceFileName.substring(typeNameStart); } } ICompilationUnit workingCopy = (ICompilationUnit) this.workingCopies.get(qualifiedTypeName); if (workingCopy != null) { answer = new NameEnvironmentAnswer(workingCopy, null /*no access restriction*/); } else { answer = location.findClass(sourceFileName, // doesn't include the file extension qPackageName, qSourceFileName); // doesn't include the file extension } } else { if (binaryFileName == null) { qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class; binaryFileName = qBinaryFileName; qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class" qPackageName = qBinaryFileName.substring(0, typeNameStart - 1); binaryFileName = qBinaryFileName.substring(typeNameStart); } } answer = location.findClass(binaryFileName, qPackageName, qBinaryFileName); } if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer)) // remember suggestion and keep looking suggestedAnswer = answer; } } if (suggestedAnswer != null) // no better answer was found return suggestedAnswer; return null; }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianNameEnvironment.java
License:Open Source License
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) { if (this.notifier != null) this.notifier.checkCancelWithinCompiler(); if (this.initialTypeNames != null && this.initialTypeNames.includes(qualifiedTypeName)) { if (this.isIncrementalBuild) // catch the case that a type inside a source file has been // renamed but other class files are looking for it throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedTypeName)); return null; // looking for a file which we know was provided at the // beginning of the compilation }// w w w . ja v a 2 s . c o m if (this.additionalUnits != null && this.sourceLocations.length > 0) { // if an additional source file is waiting to be compiled, answer it // BUT not if this is a secondary type search // if we answer X.java & it no longer defines Y then the binary type // looking for Y will think the class path is wrong // let the recompile loop fix up dependents when the secondary type // Y has been deleted from X.java SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /* no access restriction*/); } String qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class; String binaryFileName = qBinaryFileName; String qPackageName = ""; //$NON-NLS-1$ if (qualifiedTypeName.length() > typeName.length) { int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class" qPackageName = qBinaryFileName.substring(0, typeNameStart - 1); binaryFileName = qBinaryFileName.substring(typeNameStart); } NameEnvironmentAnswer suggestedAnswer = null; for (int i = 0, l = this.binaryLocations.length; i < l; i++) { NameEnvironmentAnswer answer = this.binaryLocations[i].findClass(binaryFileName, qPackageName, qBinaryFileName); if (answer != null) { if (!answer.ignoreIfBetter()) { if (answer.isBetter(suggestedAnswer)) return answer; } else if (answer.isBetter(suggestedAnswer)) suggestedAnswer = answer; } } if (suggestedAnswer != null) return suggestedAnswer; return null; }